From ecd6ae12fbd487d759aaf347c6947a78483c1642 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Fri, 15 Nov 2024 15:03:03 +0000 Subject: [PATCH] nir/algebraic: fix iabs(ishr(iabs(a), b)) optimization iabs(a) is not positive if "a" is the minimum signed value, so this is incorrect in that case for some values of "b". Signed-off-by: Rhys Perry Reviewed-by: Ian Romanick Fixes: 2b76de9b5dd5 ("nir/algebraic: Add a couple optimizations for iabs and ishr") Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 01821eaada2..5eb501dea5a 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1327,7 +1327,8 @@ optimizations.extend([ # negative. (('bcsel', ('ilt', a, 0), ('ineg', ('ishr', a, b)), ('ishr', a, b)), ('iabs', ('ishr', a, b))), - (('iabs', ('ishr', ('iabs', a), b)), ('ishr', ('iabs', a), b)), + (('iabs', ('ishr', ('iabs', a), b)), ('ushr', ('iabs', a), b)), + (('iabs', ('ushr', ('iabs', a), b)), ('ushr', ('iabs', a), b)), (('fabs', ('slt', a, b)), ('slt', a, b)), (('fabs', ('sge', a, b)), ('sge', a, b)),