nir/algebraic: optimize ushr(a, ishl(iand(b, 3), 3))

nir_lower_mem_access_bit_sizes creates this.

No fossil-db changes.

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31904>
This commit is contained in:
Rhys Perry 2024-11-11 15:18:33 +00:00 committed by Marge Bot
parent e95a3364b8
commit 0c7830eb85

View file

@ -1193,7 +1193,7 @@ for op in ['iand', 'ior', 'ixor']:
# Integer sizes
for s in [8, 16, 32, 64]:
last_shift_bit = int(math.log2(s)) - 1
amount_bits = int(math.log2(s))
lower_umin = 'options->lower_umin'
lower_umax = 'options->lower_umax'
@ -1231,7 +1231,8 @@ for s in [8, 16, 32, 64]:
(('ishl', 'a@{}'.format(s), ('iand', s - 1, b)), ('ishl', a, b)),
(('ishr', 'a@{}'.format(s), ('iand', s - 1, b)), ('ishr', a, b)),
(('ushr', 'a@{}'.format(s), ('iand', s - 1, b)), ('ushr', a, b)),
(('ushr', 'a@{}'.format(s), ('ishl(is_used_once)', ('iand', b, 1), last_shift_bit)), ('ushr', a, ('ishl', b, last_shift_bit))),
(('ushr', 'a@{}'.format(s), ('ishl(is_used_once)', ('iand', b, 1), amount_bits - 1)), ('ushr', a, ('ishl', b, amount_bits - 1))),
(('ushr', 'a@{}'.format(s), ('ishl(is_used_once)', ('iand', b, 3), amount_bits - 2)), ('ushr', a, ('ishl', b, amount_bits - 2))),
])
optimizations.extend([