RFR: 8346664: C2: Optimize mask check with constant offset [v5]
Matthias Ernst
duke at openjdk.org
Fri Jan 24 16:17:53 UTC 2025
On Fri, 24 Jan 2025 16:05:57 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:
>> src/hotspot/share/opto/mulnode.cpp line 2112:
>>
>>> 2110:
>>> 2111: jint zeros = AndIL_min_trailing_zeros(phase, expr, bt);
>>> 2112: return zeros > 0 && ((((jlong)1) << zeros) > mask_t->hi_as_long() && mask_t->lo_as_long() >= 0);
>>
>> FWIW I came up with another way to formulate this. I think it makes even more clear how this is all about "expr is shifted to be completely left of the mask", i.e. we're comparing right-most value bit position to left-most mask bit position, all other bits are irrelevant.
>>
>> This could also inform how to bias the random generator. Let me know what you think.
>>
>> Suggestion:
>>
>> jint expr_trailing_zeros = AndIL_min_trailing_zeros(phase, expr, bt);
>> if (expr_trailing_zeros == 0) return false;
>>
>> const TypeInteger* mask_t = phase->type(mask)->isa_integer(bt);
>> if (mask_t == nullptr || mask_t->lo_as_long() < 0) return false;
>>
>> jint mask_bit_width = mask_t->hi_as_long() == 0 ? 0 : (BitsPerLong - count_leading_zeros(mask_t->hi_as_long()));
>> return expr_trailing_zeros >= mask_bit_width;
>
> `mask_t->lo_as_long() == 0` does not imply `mask == 0`, though. Other than that I think it is a great suggestion.
You're right. Fixed above. I was trying to get around special casing 0 (count_*_zeros don't like them).
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22856#discussion_r1928929675
More information about the hotspot-compiler-dev
mailing list