RFR: 8373999: C2: apply KnownBits and unsigned bounds to Add / Sub operations [v4]

Quan Anh Mai qamai at openjdk.org
Wed Jan 14 13:42:29 UTC 2026


On Wed, 14 Jan 2026 12:38:18 GMT, Benoît Maillard <bmaillard at openjdk.org> wrote:

>> Quan Anh Mai has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
>> 
>>  - copyright year
>>  - Merge branch 'master' into addsub
>>  - Merge branch 'master' into addsub
>>  - include order
>>  - Improve Add/SubNode::Value with unsigned bounds and known bits
>
> src/hotspot/share/opto/rangeinference.hpp line 437:
> 
>> 435:         // non-negative, the signed addition does not overflow, we can compute it directly.
>> 436:         lo = S<CTP>(st1._ulo + st2._ulo);
>> 437:         hi = S<CTP>(st1._uhi + st2._uhi);
> 
> Why not use the signed bounds directly since they are equal anyway? I find it a bit easier to read, and we can avoid the cast.
> Suggestion:
> 
>         lo = st1._lo + st2._lo;
>         hi = st1._hi + st2._hi;

It is because `st1._lo` can be a 3-bit signed `int`. And I don't want to implement arithmetic for these signed classes since normally signed arithmetic is UB in the presence of overflow. And it seems not a good idea to either introduce UB for `int3_t` addition, or have inconsistent behaviour between things we test with and things that are the real guys.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28897#discussion_r2690469664


More information about the hotspot-compiler-dev mailing list