RFR: 8267332: xor value should handle bounded values [v2]

Claes Redestad redestad at openjdk.java.net
Thu May 20 21:53:58 UTC 2021


On Thu, 20 May 2021 21:50:46 GMT, Nils Eliasson <neliasso at openjdk.org> wrote:

>> In the discussion of https://github.com/openjdk/jdk/pull/3938 a limitation in C2 was found. C2 fails to eliminate obvious bound checks for indexes that are masked with xor.
>> 
>> The Xor for two values that have a lower bound of zero or more, the resulting lower bound is zero.
>> The Xor for two values that have a upperbound above zero, the resulting upper bound is the max of the next_power_of_2-1.
>> 
>> Test supplied. 
>> 
>> Please review,
>> Best regards,
>> Nils Eliasson
>
> Nils Eliasson has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix bounds check

src/hotspot/share/opto/addnode.cpp line 929:

> 927:   if ((t1i->_lo >= 0)        &&
> 928:       (t1i->_hi > 0)         &&
> 929:       (t1i->_hi <= max_power_of_2<jint>()) &&

I think you could use `<= std::numeric_limits<T>::max()` as the upper bound condition, and use `(jint)(next_power_of_2((uint)t1i->_hi) - 1)` to produce the mask in an overflow-conscious way.

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

PR: https://git.openjdk.java.net/jdk/pull/4136


More information about the hotspot-compiler-dev mailing list