RFR: 8347555: [REDO] C2: implement optimization for series of Add of unique value [v5]
Kangcheng Xu
kxu at openjdk.org
Thu Mar 6 21:45:28 UTC 2025
On Tue, 4 Mar 2025 08:29:00 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> Kangcheng Xu has updated the pull request incrementally with one additional commit since the last revision:
>>
>> remove tri-conditionals
>
> This looks interesting! Thanks @tabjy for the work!
>
> For now, I just have some drive-through comments about testing.
>
> Also: would it make sense to have a JMH benchmark to prove that this code change is beneficial enough to warrant the additional complexity?
Added randomized tests per @eme64's suggestions. I'm still looking into micro benchmark with JMH
> test/hotspot/jtreg/compiler/c2/TestSerialAdditions.java line 291:
>
>> 289: return i + (x << i) + i; // Expects 64 + 63 + 64 = 191
>> 290: }
>> 291: }
>
> Would it make sense to add some randomized patterns, just for result verification?
>
> You can use `Generators.java` to get interesting values. Of course that would mean not doing IR verification, but at least it would give us better confidence that the values are correct.
>
> I'm imagining expressions like this:
> `return a * CON1 + a * CON2 + a * CON3 + a * CON4`
>
> Where the CON are defined as a `public static final` field with a random value generated by `Generators`.
>
> The advantage of using `Generators` is that it generates powers-of-two more frequently, which seems to be relevant here.
That's a very valid suggestion. Thanks. I updated the test. Please take a look if I understood your intention correctly.
However, it does look like this `a * CON1 + a * CON2 + ...` pattern is picked up by existing the associative optimization first:
https://github.com/openjdk/jdk/blob/a23fb0af65f491ef655ba114fcc8032a09a55213/src/hotspot/share/opto/addnode.cpp#L345-L377
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23506#issuecomment-2705006453
PR Review Comment: https://git.openjdk.org/jdk/pull/23506#discussion_r1984090578
More information about the hotspot-compiler-dev
mailing list