RFR: 8346664: C2: Optimize mask check with constant offset [v17]
Emanuel Peter
epeter at openjdk.org
Wed Feb 5 08:19:20 UTC 2025
On Wed, 5 Feb 2025 08:03:43 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> src/hotspot/share/opto/mulnode.cpp line 2102:
>>
>>> 2100: // (AndL (ConL (_ << #N)) #M)
>>> 2101: // The M and N values must satisfy ((-1 << N) & M) == 0.
>>> 2102: static bool AndIL_is_zero_element_under_mask(const PhaseGVN* phase, const Node* expr, const Node* mask, BasicType bt) {
>>
>> Suggestion:
>>
>> // Checks whether expr is neutral element (zero) under mask. We have:
>> // (AndX expr mask)
>> // The X in AndX must be I or L, depending on bt.
>> //
>> // We split the bits of expr into MSB and LSB, where LSB represents
>> // all trailing zeros of expr:
>> // MSB LSB
>> // xxxxxx 0000000000
>> //
>> // We check if the mask has no one bits in the corresponding higher
>> // bits, i.e. if the number of trailing zeros is larger or equal to the
>> // bit width of the expr, i.e. if the number of leading zeros for mask
>> // is greater or equal to the number of bits in MSB:
>> // 000000 00000yyyyy -> (AndX expr mask) = 0 -> return true
>> // 0000yy yyyyyyyyyy -> (AndX expr mask) = 0000zz 0000000000 -> return false
>> //
>> static bool AndIL_is_zero_element_under_mask(const PhaseGVN* phase, const Node* expr, const Node* mask, BasicType bt) {
>
> I would leave any details about `addition` to the use of this function, and any discussion how we find the trailing zeros to `AndIL_min_trailing_zeros`. Otherwise it's a little confusing.
>
> It's nice to have examples, and give the reader an intuition of what you are doing in the logic below.
Feel free to tweak the description further ;)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22856#discussion_r1942418028
More information about the hotspot-compiler-dev
mailing list