Mesa (staging/21.2): nir/algebraic: fix imod by negative power-of-two
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Aug 9 21:46:59 UTC 2021
Module: Mesa
Branch: staging/21.2
Commit: 8446f10145b910c40b7efc9600f50e07fe321f87
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8446f10145b910c40b7efc9600f50e07fe321f87
Author: Rhys Perry <pendingchaos02 at gmail.com>
Date: Wed Jul 21 17:06:30 2021 +0100
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 <pendingchaos02 at gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Fixes: 0ef5f3552f6 ("nir: add strength reduction pattern for imod/irem with pow2 divisor.")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12039>
(cherry picked from commit ec4b425f596d5bbe4c2401b9cfc08d7c9eaa36b0)
---
.pick_status.json | 2 +-
src/compiler/nir/nir_opt_algebraic.py | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index b6df30d44d6..3eb8ef0cd55 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -355,7 +355,7 @@
"description": "nir/algebraic: fix imod by negative power-of-two",
"nominated": true,
"nomination_type": 1,
- "resolution": 0,
+ "resolution": 1,
"main_sha": null,
"because_sha": "0ef5f3552f68076747211ec81f687b37a5540d8e"
},
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index eef8027c7f6..31e9d83e454 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),
More information about the mesa-commit
mailing list