RFR: 8347555: [REDO] C2: implement optimization for series of Add of unique value [v9]

Kangcheng Xu kxu at openjdk.org
Thu Apr 10 19:13:21 UTC 2025


On Wed, 2 Apr 2025 10:15:31 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> Kangcheng Xu has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   fix ((x<<y) << z) + (x<<y) patterns
>
> src/hotspot/share/opto/addnode.cpp line 431:
> 
>> 429:     Node* con = (bt == T_INT)
>> 430:                 ? (Node*) phase->intcon((jint) (mul.multiplier + 1)) // intentional type narrowing to allow overflow at max_jint
>> 431:                 : (Node*) phase->longcon((mul.multiplier + 1));
> 
> I think just to be safe, you should use `java_add` to have correct overflow semantics. You are using `jlong` for `multiplier`, which is a signed integer type, and in C++ overflow is undefined behavior as far as I know, let's avoid that ;)
> 
> Actually, do you have a test where the multiplier overflows here?

Good point regarding UB. Updated to use `java_add`.

There are several test cases named `.*Overflow()` in `TestSerialAdditions`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23506#discussion_r2038121769


More information about the hotspot-compiler-dev mailing list