If we manage to fold in a left shift that's bigger than the hardware can do, we
should at least avoid generating a useless right shift to feed the hardware
rather bailing completely.
For motivation, this form of address arithmetic is encountered when indexing
into arrays with large power-of-two element sizes (array-of-structs).
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21643>
if (new_shift <= 2) {
match.offset = shifted;
match.shift = new_shift;
+ } else if (new_shift > 0) {
+ /* For large shifts, we do need an ishl instruction but we can
+ * shrink the shift to avoid generating an ishr.
+ */
+ assert(new_shift >= 3);
+
+ nir_ssa_def *rewrite =
+ nir_ishl_imm(b, nir_vec_scalars(b, &shifted, 1), new_shift);
+
+ match.offset = nir_get_ssa_scalar(rewrite, 0);
+ match.shift = 0;
}
}
} else {