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

Quan Anh Mai qamai at openjdk.org
Thu May 1 10:48:46 UTC 2025


On Thu, 1 May 2025 08:04:02 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> src/hotspot/share/opto/rangeinference.cpp line 454:
>> 
>>> 452:   // it
>>> 453:   U new_zeros = bits._zeros | (match_mask & ~bounds._lo);
>>> 454:   U new_ones = bits._ones | (match_mask & bounds._lo);
>> 
>> Suggestion:
>> 
>>   U common_prefix = match_mask & bounds._lo;
>>   assert(common_prefix == match_mask & bounds._lo, "common prefix of both");
>>   U neg_common_prefix = match_mask & ~bounds._lo;
>>   assert(neg_common_prefix == match_mask & ~bounds._lo, "common negated prefix of both");
>>   U new_zeros = bits._zeros | neg_common_prefix;
>>   U new_ones = bits._ones | common_prefix;
>> 
>> Just an idea. Up to you.
>
> Hmm, I think your solution is understandable already, not sure mine is better. I'll still leave it for you here, feel free to mark it resolved.

Nice suggestions, I have done so with a little modification.

>> src/hotspot/share/opto/rangeinference.cpp line 509:
>> 
>>> 507:   // Trivially canonicalize the bounds so that srange._lo and urange._hi are
>>> 508:   // both < 0 or >= 0. The same for srange._hi and urange._ulo. See TypeInt for
>>> 509:   // detailed explanation.
>> 
>> You seem to suggest that `urange._hi` can be `< 0`. But it is unsigned, so that is confusing.
>> This looks like Lemma 3 from TypeInt is relevant here, right? You might want to state that here,
>> and still also bring this ASCII art up again here:
>> 
>>  *     Signed:
>>  *     -----lo=========uhi---------0--------ulo==========hi-----
>>  *     Unsigned:
>>  *                                 0--------ulo==========hi----------lo=========uhi---------
>> 
>> Also, does `S(urange._lo) > S(urange._hi)` imply `U(srange._lo) > U(srange._hi)`?
>> - If yes, assert it!
>> - If no: are we missing an optimization?
>
> It could also be that I'm missing some things here... So it could be good to refer to the exact things in `TypeInt` and the Lemma numbers you are using here. Otherwise it is a lot of work for the reader to check what you are doing here.

Here the bounds may take any value, so we cannot have S(urange._lo) > S(urange._hi) imply U(srange._lo) > U(srange._hi) yet. I hope the description I have done is now clearer.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17508#discussion_r2070137968
PR Review Comment: https://git.openjdk.org/jdk/pull/17508#discussion_r2070143606


More information about the hotspot-compiler-dev mailing list