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

Quan Anh Mai qamai at openjdk.org
Fri May 2 16:35:29 UTC 2025


On Fri, 2 May 2025 15:30:55 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> src/hotspot/share/opto/rangeinference.cpp line 398:
>> 
>>> 396:     // This is the result we are looking for.
>>> 397:     //           1 0 1 0 0 0 1 1
>>> 398:     new_lo |= bits._ones;
>> 
>> Now we should probably also split the cases with and without candidates.
>> Suggestion:
>> 
>>     // Assume there was at least one candidate, and i is the index of the last one:
>>     // Then there exists no value x not larger than i such that
>>     // new_lo[x] == 0 and ones[x] == 1. This is because all bits of lo before i
>>     // should satisfy bits, and new_lo[i] == 1. As a result, doing
>>     // new_lo |= bits.ones will give us a value such that:
>>     // - new_lo[x] = lo[x], for 0 <= x < i (2.5)
>>     // - new_lo[i] = 1                     (2.6)
>>     // - new_lo[x] = ones[x], for x > i    (2.7)
>>     // This is the result r we are looking for.
>>     //           1 0 1 0 0 0 1 1
>>     // If there was no candidate, then above we had new_lo = 0, and the
>>     // computation below gives us new_lo = ones.
>>     new_lo |= bits._ones;
>
> The "no candidate" case should now have an argument why this is an ok value to return.
> It does satisfy bits, since `ones` satisfy bits.
> But do we know that `ones < lo`? We need that to get the "overflow" we promised at the very top of the method.

You are diverting too much from the base assumption of this function. Formally, this function assumes that a result exists, which means that `i` exists, which leads to `tmp != 0`. The converse is also true, if `tmp != 0`, an index value `i` exists, which leads to a value not smaller than `lo` and satisfies `bits`. This implies that there does not exist one such value if and only if `tmp == 0`. In that case we know exactly that what we return satisfies bits. That's all we need to know in this section.

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

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


More information about the hotspot-compiler-dev mailing list