RFR: 8315066: Add unsigned bounds and known bits to TypeInt/Long [v53]
Emanuel Peter
epeter at openjdk.org
Thu May 1 07:51:59 UTC 2025
On Thu, 1 May 2025 07:00:46 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 two additional commits since the last revision:
>
> - wording
> - grammar, more details for non-existence
Two minor suggestions for the proof around `new_hi`. I think the added proof helps, thanks for adding it :)
src/hotspot/share/opto/rangeinference.cpp line 416:
> 414: //
> 415: // 2. Assume there is a value k that is larger than ~h such that k is not
> 416: // larger than hi and k satisfies {bits._zeros, bits._ones}. As a result, ~k
Suggestion:
// 2. Assume there is a value k that is larger than ~h such that k is not
// larger than hi, i.e. ~h < k <= hi and k satisfies {bits._zeros, bits._ones}. As a result, ~k
Just to help the reader a little.
src/hotspot/share/opto/rangeinference.cpp line 424:
> 422: // As a result, ~h is the largest value not larger than hi that satisfies
> 423: // bits (QED).
> 424: U new_hi = ~adjust_lo(~bounds._hi, {bits._ones, bits._zeros});
Suggestion:
U h = adjust_lo(~bounds._hi, {bits._ones, bits._zeros})
U new_hi = ~h;
Just to tie it in to your proof from above.
-------------
PR Review: https://git.openjdk.org/jdk/pull/17508#pullrequestreview-2809297171
PR Review Comment: https://git.openjdk.org/jdk/pull/17508#discussion_r2069947334
PR Review Comment: https://git.openjdk.org/jdk/pull/17508#discussion_r2069945068
More information about the hotspot-compiler-dev
mailing list