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

Benoît Maillard bmaillard at openjdk.org
Thu Jan 15 08:39:02 UTC 2026


On Wed, 14 Jan 2026 13:36:11 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

>> Hi,
>> 
>> This PR improves the implementation of `AddNode/SubNode::Value` by taking advantage of the additional information in `TypeInt`. The implementation has some pretty non-trivial logic. Fortunately, the test infrastructure is already there.
>> 
>> Please take a look and leave your reviews, thanks a lot.
>
> Quan Anh Mai has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Improve comments

src/hotspot/share/opto/rangeinference.hpp line 496:

> 494:       // min_carry[i - 1] == 1 iff either:
> 495:       // + (st1._bits._ones[i] & st2._bits._ones[i]) == 1
> 496:       // + ((st1._bits._ones[i] | st2._bits._ones[i]) & (~tmp[i])) == 1

Suggestion:

      // + ((st1._bits._ones[i] ^ st2._bits._ones[i]) & (~tmp[i])) == 1

src/hotspot/share/opto/rangeinference.hpp line 499:

> 497:       //
> 498:       // As a result, we can calculate min_carry:
> 499:       // min_carry = ((st1._bits._ones & st2._bits._ones) | ((st1._bits._ones | st2._bits._ones) & (~(st1._bits._ones + st2._bits._ones)))) << 1

Suggestion:

      // min_carry = ((st1._bits._ones & st2._bits._ones) | ((st1._bits._ones ^ st2._bits._ones) & (~(st1._bits._ones + st2._bits._ones)))) << 1

src/hotspot/share/opto/rangeinference.hpp line 501:

> 499:       // min_carry = ((st1._bits._ones & st2._bits._ones) | ((st1._bits._ones | st2._bits._ones) & (~(st1._bits._ones + st2._bits._ones)))) << 1
> 500:       U<CTP> min_carry = ((st1._bits._ones & st2._bits._ones) |
> 501:                           ((st1._bits._ones | st2._bits._ones) & (~(st1._bits._ones + st2._bits._ones))));

Suggestion:

                          ((st1._bits._ones ^ st2._bits._ones) & (~(st1._bits._ones + st2._bits._ones))));

src/hotspot/share/opto/rangeinference.hpp line 505:

> 503:       // Similarly, we can calculate max_carry from ~st1._bits._zeros and ~st2._bits._zeros
> 504:       U<CTP> max_carry = ((~st1._bits._zeros & ~st2._bits._zeros) |
> 505:                           ((~st1._bits._zeros | ~st2._bits._zeros) & (~(~st1._bits._zeros + ~st2._bits._zeros))));

Suggestion:

                          ((~st1._bits._zeros ^ ~st2._bits._zeros) & (~(~st1._bits._zeros + ~st2._bits._zeros))));

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28897#discussion_r2693431904
PR Review Comment: https://git.openjdk.org/jdk/pull/28897#discussion_r2693433557
PR Review Comment: https://git.openjdk.org/jdk/pull/28897#discussion_r2693434441
PR Review Comment: https://git.openjdk.org/jdk/pull/28897#discussion_r2693435496


More information about the hotspot-compiler-dev mailing list