RFR: 8299179: ArrayFill with store on backedge needs to reduce length by 1 [v2]

Dean Long dlong at openjdk.org
Tue Jan 10 23:14:13 UTC 2023


On Tue, 10 Jan 2023 14:35:21 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).
>
> Emanuel Peter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix indentation
>   
>   Co-authored-by: Tobias Hartmann <tobias.hartmann at oracle.com>

src/hotspot/share/opto/loopTransform.cpp line 4389:

> 4387:   if (store->in(0) == backedge) {
> 4388:     len = new SubINode(len, _igvn.intcon(1));
> 4389:     _igvn.register_new_node_with_optimizer(len);

How about moving the earlier call to register_new_node_with_optimizer to after this block, so it is only called once?

-------------

PR: https://git.openjdk.org/jdk/pull/11904


More information about the hotspot-compiler-dev mailing list