RFR: 8346664: C2: Optimize mask check with constant offset [v17]
Matthias Ernst
duke at openjdk.org
Wed Feb 5 17:28:17 UTC 2025
On Wed, 5 Feb 2025 09:19:01 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
> Mabe we can adjust the name of `AndIL_is_zero_element_under_mask` somehow, so that the assumption is made explicit?
My math isn't super strong. I do find the name "zero element" more compelling to the previous "is_always_zero", since zero element seems to be a well-known term: https://en.wikipedia.org/wiki/Zero_element . That page also uses "Additive Identity", happy to use that term, or, "is_neutral_wrt_addition_under_mask" . The important part is, as you and @merykitty much earlier correctly point out, is that `add1&mask==0` is _not_ sufficient, there needs to implied a "for all" quantifier.
I would be happiest if we can
* explicitly stress that is_zero_lement (or whatever name we choose) can return false negatives, we're not trying to determine this for arbitrary expr/mask combos,
* that it is primarily covering the case "mask = 2^X-1" aka "% 2^x" (that's what we get for alignment checks) => it means we're testing whether `expr` is a multiple of `2^X` => is "congruent to zero modulo (mask+1)" ([modular arithmetic](https://en.wikipedia.org/wiki/Modular_arithmetic)). That is the motivating (and maybe only case that matters), and we could stop there.
* But we can document that this version takes it one step further, namely the same is trivially implied if there's some bits "missing" in mask. Hence the check is whether `expr` is a multiple of `2 ^ log2 mask` (equiv num_trailing_bits >= mask_width).
-------------
PR Comment: https://git.openjdk.org/jdk/pull/22856#issuecomment-2637569499
More information about the hotspot-compiler-dev
mailing list