RFR: 8367341: C2: apply KnownBits and unsigned bounds to And / Or operations [v2]

Emanuel Peter epeter at openjdk.org
Wed Oct 15 12:14:46 UTC 2025


On Wed, 15 Oct 2025 09:06:09 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

>> Hi,
>> 
>> This PR improves the implementation of `AndNode/OrNode/XorNode::Value` by taking advantages of the additional information in `TypeInt`. The implementation is pretty straightforward. A clever trick is that by analyzing the negative and positive ranges of a `TypeInt` separately, we have better info for the leading bits. I also implement gtest unit tests to verify the correctness and monotonicity of the inference functions.
>> 
>> 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:
> 
>   Emanuel's reviews

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

> 356:       U<CTP> ulo = std::numeric_limits<U<CTP>>::min();
> 357:       // The unsigned value of the result of 'and' is always not greater than both of its inputs
> 358:       // since there is no position at which the bit is 1 in the result and 0 in either input

That does not sound correct.

We could have ranges `0..0b1000` for both. But then both values are `0b0010`, and so the result is `0b0010`, which is a 1 at a position where both `uhi` values had zeros.

I think you need to talk about leading zeros somehow.

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

> 370:       S<CTP> hi = std::numeric_limits<S<CTP>>::max();
> 371:       // The unsigned value of the result of 'or' is always not less than both of its inputs since
> 372:       // there is no position at which the bit is 0 in the result and 1 in either input

Same issue here as above

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27618#discussion_r2432314546
PR Review Comment: https://git.openjdk.org/jdk/pull/27618#discussion_r2432315446


More information about the hotspot-compiler-dev mailing list