RFR: 8347555: [REDO] C2: implement optimization for series of Add of unique value [v7]
Emanuel Peter
epeter at openjdk.org
Thu Mar 13 09:11:54 UTC 2025
On Tue, 11 Mar 2025 19:49:41 GMT, Kangcheng Xu <kxu at openjdk.org> wrote:
>> [JDK-8347555](https://bugs.openjdk.org/browse/JDK-8347555) is a redo of [JDK-8325495](https://bugs.openjdk.org/browse/JDK-8325495) was [first merged](https://git.openjdk.org/jdk/pull/20754) then backed out due to a regression. This patch redos the feature and fixes the bit shift overflow problem. For more information please refer to the previous PR.
>>
>> When constanlizing multiplications (possibly in forms on `lshifts`), the multiplier is upgraded to long and then later narrowed to int if needed. However, when a `lshift` operand is exactly `32`, overflowing an int, using long has an unexpected result. (i.e., `(1 << 32) = 1` and `(int) (1L << 32) = 0`)
>>
>> The following was implemented to address this issue.
>>
>> if (UseNewCode2) {
>> *multiplier = bt == T_INT
>> ? (jlong) (1 << con->get_int()) // loss of precision is expected for int as it overflows
>> : ((jlong) 1) << con->get_int();
>> } else {
>> *multiplier = ((jlong) 1 << con->get_int());
>> }
>>
>>
>> Two new bitshift overflow tests were added.
>
> Kangcheng Xu has updated the pull request incrementally with one additional commit since the last revision:
>
> add micro benchmark
test/hotspot/jtreg/compiler/c2/TestSerialAdditions.java line 310:
> 308: CON3_L = genL.next();
> 309: CON4_L = genL.next();
> 310: }
Is there a reason why you are restricting the values to `powerOfTwoLongs`? I think it would be better if you just take the most general generator.
private static final RestrictableGenerator<Integer> GEN_INT = Generators.G.ints();
private static final RestrictableGenerator<Long> GEN_LONG = Generators.G.longs();
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23506#discussion_r1993077366
More information about the hotspot-compiler-dev
mailing list