RFR: 8335444: Generalize implementation of AndNode mul_ring [v3]

Quan Anh Mai qamai at openjdk.org
Fri Aug 23 17:56:08 UTC 2024


On Thu, 22 Aug 2024 20:24:14 GMT, Jasmine Karthikeyan <jkarthikeyan at openjdk.org> wrote:

>> Can the upper limit be improved similar to what you added for the "both ranges are positive" case if we know that both ranges are negative?
>> In the positive case, we have values from:
>> 
>> 011...1
>> 000...0
>> ``` 
>> while in the negative case, we have values from:
>> 
>> 111...1
>> 100...0
>> 
>> It suggests that we can then use the same argument as for the positive case and say that the maximum will be the maximum of the smaller range (i.e. `MIN2(r0->_hi, r1->_hi)`?
>
> This is a great observation! Since bitwise-and can only remove bits, the largest possible value is the smaller of each range's `hi` value so I think it's correct to use the minimum here rather than the maximum. I didn't look into this case too deeply initially since I didn't find any bitwise-and nodes of two negative ranges in my investigation, but I think we should include it since it's a simple enough condition to check.

Another point of view, you can decompose `[lo, hi]` into `[lo, -1] v [0, hi]`. Then `[lo1, hi1] & [lo2, hi2]` can be calculated as:

    ([lo1, -1] & [lo2, -1]) v ([lo1, -1] & [0, hi2]) v ([0, hi1] & [lo2, -1]) v ([0, hi1] & [0, hi2]) =
    [lo, -1] v [0, hi2] v [0, h1] v [0, min(hi1, hi2)] =
    [lo, max(hi1, hi2)]`

with `lo` being the lower bound you calculated right above.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20066#discussion_r1729328074


More information about the hotspot-compiler-dev mailing list