RFR: 8315066: Add unsigned bounds and known bits to TypeInt/Long [v18]
Jatin Bhateja
jbhateja at openjdk.org
Wed Sep 11 05:35:12 UTC 2024
On Tue, 10 Sep 2024 18:03: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:
>
> remove leftover code
I will spend some time to go over your patch in detail, some early comments.
src/hotspot/share/opto/rangeinference.hpp line 69:
> 67: return (v & _zeros) == 0 && (v & _ones) == _ones;
> 68: }
> 69: };
It will be good if we add basic operations to KnowBits like.
KnownBits.getMaxValue() returning ~ZEROS
KnownBits.getMinValue() returning ONE
KnownBits.and(KnownBits arg)
KnownBits.or(KnownBits arg)
KnownBits.xor(KnownBits args)
KnownBits.not()
These can be quite handy during data flow analysis using KnownBits
src/hotspot/share/opto/type.hpp line 661:
> 659: // the below constraints, see contains(jint)
> 660: const jint _lo, _hi; // Lower bound, upper bound in the signed domain
> 661: const juint _ulo, _uhi; // Lower bound, upper bound in the unsigned domain
Can't we do without explicit fields to record unsigned hi / lo ?
We just need to present a unsigned view of signed _lo and _hi which can be done using safe macros.
-------------
PR Review: https://git.openjdk.org/jdk/pull/17508#pullrequestreview-2293022456
PR Review Comment: https://git.openjdk.org/jdk/pull/17508#discussion_r1753137705
PR Review Comment: https://git.openjdk.org/jdk/pull/17508#discussion_r1753141704
More information about the hotspot-compiler-dev
mailing list