RFR: 8315066: Add unsigned bounds and known bits to TypeInt/Long [v52]
Emanuel Peter
epeter at openjdk.org
Thu May 1 06:23:00 UTC 2025
On Wed, 30 Apr 2025 16:11:45 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:
>
> alignment note
Thanks for the updates, looks much better already :)
Left some suggestions for `a such` -> `such a`.
src/hotspot/share/opto/rangeinference.cpp line 91:
> 89: //
> 90: // If there exists a value not less than lo and satisfies bits, then this
> 91: // function will always find a such value. The conversion is also true, that is
Suggestion:
// function will always find such a value. The conversion is also true, that is
src/hotspot/share/opto/rangeinference.cpp line 93:
> 91: // function will always find a such value. The conversion is also true, that is
> 92: // if this function finds a value not less than lo and satisfies bits, then it
> 93: // must trivially be the case that there exists a such value. As a result, the
Suggestion:
// must trivially be the case that there exists such a value. As a result, the
src/hotspot/share/opto/rangeinference.cpp line 96:
> 94: // negation of those statements are also equivalent, there does not exists a
> 95: // value not less than lo and satisfies bits if and only if this function does
> 96: // not return a such value.
Suggestion:
// not return such a value.
src/hotspot/share/opto/rangeinference.cpp line 99:
> 97: //
> 98: // In practice, since the algorithm always ensures that the returned value
> 99: // satisfies bits, we only need to check if it is not less than lo.
Ah nice. Ok. So now we just have to prove that the result satisfies bits in all cases :)
-------------
PR Review: https://git.openjdk.org/jdk/pull/17508#pullrequestreview-2809219375
PR Review Comment: https://git.openjdk.org/jdk/pull/17508#discussion_r2069889936
PR Review Comment: https://git.openjdk.org/jdk/pull/17508#discussion_r2069890407
PR Review Comment: https://git.openjdk.org/jdk/pull/17508#discussion_r2069890666
PR Review Comment: https://git.openjdk.org/jdk/pull/17508#discussion_r2069893090
More information about the hotspot-compiler-dev
mailing list