diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index cd52925972a..f70d29101b4 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -102,10 +102,17 @@ optimizations = [ (('idiv', a, 1), a), (('umod', a, 1), 0), (('imod', a, 1), 0), + (('imod', a, -1), 0), + (('irem', a, 1), 0), + (('irem', a, -1), 0), (('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))), + (('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))), (('~fneg', ('fneg', a)), a), (('ineg', ('ineg', a)), a),