RFR: 8347459: C2: missing transformation for chain of shifts/multiplications by constants [v6]
Emanuel Peter
epeter at openjdk.org
Fri Mar 7 13:54:59 UTC 2025
On Fri, 7 Mar 2025 13:49:05 GMT, Marc Chevalier <duke at openjdk.org> wrote:
>> test/hotspot/jtreg/compiler/c2/irTests/LShiftLNodeIdealizationTests.java line 222:
>>
>>> 220: public long testDoubleShift9(long x) {
>>> 221: return (x << 62L) << 3L;
>>> 222: }
>>
>> I see that you have quite a few examples here with fixed constants. It would be good to extend this with random constants. You can do that with `static final` fields, as they are constant by the time we JIT compile.
>>
>>
>> private static final int CON0 = RANDOM.nextInt();
>> private static final int CON1 = RANDOM.nextInt();
>>
>> @Test
>> public long test(int x) {
>> return (x << CON0) << CON1;
>> }
>>
>> I would give you "bonus points" if you use `Generators.java`, because that produces more interesting constants.
>
> I can also do that, but I think using the constants is more valuable than only random numbers: most of random int or long won't have some corner properties I try to cover here. On top of that, with the comments, they help enumerating clearly different cases to look at. So, I'd be happy to add some randomization, but I strongly feel I should keep the constant ones as well.
Absolutely, please keep the cases you already have, and add some randomized cases on top of it.
> most of random int or long won't have some corner properties I try to cover here
Right, that's why it is better to use `Generators.java` rather than just `Random`. With `Generators`, we make sure to generate more special values, such as powers of 2. And powers of 2 multiplication can for example be converted to shift, and that seems to be quite relevant here ;)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23728#discussion_r1985097087
More information about the hotspot-compiler-dev
mailing list