RFR: 8328528: C2 should optimize long-typed parallel iv in an int counted loop [v23]
Christian Hagedorn
chagedorn at openjdk.org
Fri Oct 18 16:32:56 UTC 2024
On Wed, 16 Oct 2024 15:18:52 GMT, Kangcheng Xu <kxu at openjdk.org> wrote:
>> Currently, parallel iv optimization only happens in an int counted loop with int-typed parallel iv's. This PR adds support for long-typed iv to be optimized.
>>
>> Additionally, this ticket contributes to the resolution of [JDK-8275913](https://bugs.openjdk.org/browse/JDK-8275913). Meanwhile, I'm working on adding support for parallel IV replacement for long counted loops which will depend on this PR.
>
> Kangcheng Xu has updated the pull request incrementally with one additional commit since the last revision:
>
> requires c2 enabled for IR tests
Two suggestions but otherwise, looks good to me, too.
src/hotspot/share/opto/loopnode.cpp line 3951:
> 3949: // int a = init2
> 3950: // for (int phi = init; phi < limit; phi += stride_con) {
> 3951: // a = init2 + (phi - init) * (stride_con2 / stride_con)
A nit but in this pseudo code, shouldn't it be the post-incremented iv (i.e. `phi + stride_con`)? Because at that point, `phi` is not incremented, yet. You eventually replace the "parallel iv" (`phi2` in the actual code) which in the graph is the pre-incremented iv. Maybe naming the iv `phi` is a little bit confusing.
You could also extend this to make it more explicit:
int iv2 = init2
int iv = init
loop:
if (phi >= limit) goto exit
phi += stride_con
iv2 = init2 + (iv - init) * (stride_con2 / stride_con)
goto loop
exit:
...
src/hotspot/share/opto/loopnode.cpp line 4036:
> 4034: jlong ratio_con = stride_con2 / stride_con;
> 4035:
> 4036: if ((ratio_con * stride_con) == stride_con2) { // Check for exact
Was like that before but it might be easier to read when we negate this into an explicit skip. Otherwise, you first need to find the closing brace to ensure that we are not doing more things for the case when it's not equal:
if ((ratio_con * stride_con) != stride_con2) {
// Not an integer multiple.
continue;
}
-------------
Marked as reviewed by chagedorn (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/18489#pullrequestreview-2378529239
PR Review Comment: https://git.openjdk.org/jdk/pull/18489#discussion_r1806747334
PR Review Comment: https://git.openjdk.org/jdk/pull/18489#discussion_r1806748330
More information about the hotspot-compiler-dev
mailing list