RFR: 8315066: Add unsigned bounds and known bits to TypeInt/Long [v48]

Emanuel Peter epeter at openjdk.org
Tue Apr 22 16:41:21 UTC 2025


On Tue, 22 Apr 2025 16:15:14 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

>> Hi,
>> 
>> This patch adds unsigned bounds and known bits constraints to TypeInt and TypeLong. This opens more transformation opportunities in an elegant manner as well as helps avoid some ad-hoc rules in Hotspot.
>> 
>> In general, a `TypeInt/Long` represents a set of values `x` that satisfies: `x s>= lo && x s<= hi && x u>= ulo && x u<= uhi && (x & zeros) == 0 && (x & ones) == ones`. These constraints are not independent, e.g. an int that lies in [0, 3] in signed domain must also lie in [0, 3] in unsigned domain and have all bits but the last 2 being unset. As a result, we must canonicalize the constraints (tighten the constraints so that they are optimal) before constructing a `TypeInt/Long` instance.
>> 
>> This is extracted from #15440 , node value transformations are left for later PRs. I have also added unit tests to verify the soundness of constraint normalization.
>> 
>> Please kindly review, thanks a lot.
>> 
>> Testing
>> 
>> - [x] GHA
>> - [x] Linux x64, tier 1-4
>
> Quan Anh Mai has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Explain what alignment means

src/hotspot/share/opto/rangeinference.cpp line 84:

> 82: // Find the minimum value that is not less than lo and satisfies bits. If there
> 83: // does not exist one such number, the calculation will overflow and return a
> 84: // value < lo.

I'm wondering if we should say anything more specific for this case. Maybe at least an example? It should probably not go here at the beginning, but somewhere further down.

src/hotspot/share/opto/rangeinference.cpp line 362:

> 360:   // not larger than hi that satisfies {bits._zeros, bits._ones}, then ~new_hi
> 361:   // is the smallest value not smaller than ~hi that satisfies
> 362:   // {bits._ones, bits._zeros}

This is a really nice high level argument. How hard do you think it would be to make it a little more detailed?
It is especially the "strictly decreasing function" argument that might not be very easy for everyone to understand...

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17508#discussion_r2054446430
PR Review Comment: https://git.openjdk.org/jdk/pull/17508#discussion_r2054458487


More information about the hotspot-compiler-dev mailing list