From 4e2b94331bad05595e2af34afb933810922c66ec Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Wed, 21 Jul 2021 17:10:39 +0100 Subject: [PATCH] nir/algebraic: improve irem by power-of-two optimization Requires one less instruction. No fossil-db changes. Signed-off-by: Rhys Perry Reviewed-by: Ian Romanick Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 225bb3efbc1..d4f2cdc384b 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -116,11 +116,14 @@ optimizations = [ (('udiv', a, '#b(is_pos_power_of_two)'), ('ushr', a, ('find_lsb', b)), '!options->lower_bitops'), (('idiv', a, '#b(is_pos_power_of_two)'), ('imul', ('isign', a), ('ushr', ('iabs', a), ('find_lsb', b))), '!options->lower_bitops'), (('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)), '!options->lower_bitops'), - (('imod', a, '#b(is_pos_power_of_two)'), ('iand', a, ('isub', b, 1)), '!options->lower_bitops'), - (('imod', a, '#b(is_neg_power_of_two)'), ('bcsel', ('ieq', ('ior', a, b), b), 0, ('ior', a, b)), '!options->lower_bitops'), - (('irem', a, '#b(is_pos_power_of_two)'), ('bcsel', ('ige', a, 0), ('iand', a, ('isub', b, 1)), ('imod', a, ('ineg', b))), '!options->lower_bitops'), - (('irem', a, '#b(is_neg_power_of_two)'), ('bcsel', ('ige', a, 0), ('iand', a, ('inot', b)), ('imod', a, b)), '!options->lower_bitops'), + (('umod', a, '#b(is_pos_power_of_two)'), ('iand', a, ('isub', b, 1)), '!options->lower_bitops'), + (('imod', a, '#b(is_pos_power_of_two)'), ('iand', a, ('isub', b, 1)), '!options->lower_bitops'), + (('imod', a, '#b(is_neg_power_of_two)'), ('bcsel', ('ieq', ('ior', a, b), b), 0, ('ior', a, b)), '!options->lower_bitops'), + # 'irem(a, b)' -> 'a - ((a < 0 ? (a + b - 1) : a) & -b)' + (('irem', a, '#b(is_pos_power_of_two)'), + ('isub', a, ('iand', ('bcsel', ('ilt', a, 0), ('iadd', a, ('isub', b, 1)), a), ('ineg', b))), + '!options->lower_bitops'), + (('irem', a, '#b(is_neg_power_of_two)'), ('irem', a, ('iabs', b)), '!options->lower_bitops'), (('~fneg', ('fneg', a)), a), (('ineg', ('ineg', a)), a),