From ec4b425f596d5bbe4c2401b9cfc08d7c9eaa36b0 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Wed, 21 Jul 2021 17:06:30 +0100 Subject: [PATCH] nir/algebraic: fix imod by negative power-of-two If "a" is a multiple of "b", then the result would have been "b" instead of 0. No fossil-db changes. Signed-off-by: Rhys Perry Reviewed-by: Ian Romanick Fixes: 0ef5f3552f6 ("nir: add strength reduction pattern for imod/irem with pow2 divisor.") Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index f2bf852ea8b..32547027679 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -114,9 +114,9 @@ optimizations = [ (('idiv', a, '#b(is_neg_power_of_two)'), ('ineg', ('imul', ('isign', a), ('ushr', ('iabs', a), ('find_lsb', ('iabs', b))))), '!options->lower_bitops'), (('umod', a, '#b(is_pos_power_of_two)'), ('iand', a, ('isub', b, 1))), (('imod', a, '#b(is_pos_power_of_two)'), ('iand', a, ('isub', b, 1))), - (('imod', a, '#b(is_neg_power_of_two)'), ('ior', a, b)), - (('irem', a, '#b(is_pos_power_of_two)'), ('bcsel', ('ige', a, 0), ('iand', a, ('isub', b, 1)), ('ior', a, ('ineg', b)))), - (('irem', a, '#b(is_neg_power_of_two)'), ('bcsel', ('ige', a, 0), ('iand', a, ('inot', b)), ('ior', a, b))), + (('imod', a, '#b(is_neg_power_of_two)'), ('bcsel', ('ieq', ('ior', a, b), b), 0, ('ior', a, b))), + (('irem', a, '#b(is_pos_power_of_two)'), ('bcsel', ('ige', a, 0), ('iand', a, ('isub', b, 1)), ('imod', a, ('ineg', b)))), + (('irem', a, '#b(is_neg_power_of_two)'), ('bcsel', ('ige', a, 0), ('iand', a, ('inot', b)), ('imod', a, b))), (('~fneg', ('fneg', a)), a), (('ineg', ('ineg', a)), a),