RFR: 8299179: ArrayFill with store on backedge needs to reduce length by 1
Tobias Hartmann
thartmann at openjdk.org
Tue Jan 10 14:01:59 UTC 2023
On Mon, 9 Jan 2023 14:48:00 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
> **Context**
> `ArrayFill` replaces `CountedLoop` like this:
> `for(int i = 5; i < 15; i++) { arr[i] = 88; }`
> with
> `jint_fill(arr, 5, len, 88)` (CallLeafNoFPNode, intrinsified)
> where `len = limit - init`.
> This is implemented for `byte`, `short` and `int` (`long` not yet supported).
>
> **Solution**
> This assumes that the `store` is in the body of the loop. In rare cases, the `store` is pinned to the backedge, and so it is executed after the exit check, hence in all iterations except the last one. In those cases we need to set `len = limit - init - 1`.
>
> **Details**
> _How does a store land on the backedge?_
> `test_002` was first reported to me. I reduced it down to a conceptually easier `test_102`.
> We have a loop, where the first block only has a single successor. This block contains the `store` that it eventually detected as a `ArrayFill`. This block passes the checks of `clone_loop_head` during parsing: the block is copied before the loop and onto the backedge.
>
> **FYI**
> I saw that we seem to currently mostly unroll such loops, instead of applying the `ArrayFill`. Follow up RFE [JDK-8299808](https://bugs.openjdk.org/browse/JDK-8299808).
Nice analysis and test. Looks good to me.
src/hotspot/share/opto/loopTransform.cpp line 4504:
> 4502: call->dump();
> 4503: }
> 4504: #endif
Suggestion:
#ifndef PRODUCT
if (TraceOptimizeFill) {
tty->print("ArrayFill call ");
call->dump();
}
#endif
-------------
Marked as reviewed by thartmann (Reviewer).
PR: https://git.openjdk.org/jdk/pull/11904
More information about the hotspot-compiler-dev
mailing list