Mesa (staging/22.1): nir/algebraic: Fix NaN-unsafe fcsel patterns
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Jun 23 16:19:37 UTC 2022
Module: Mesa
Branch: staging/22.1
Commit: ac10f5a3ab11ae1422452f4cac1099ca27313d2b
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=ac10f5a3ab11ae1422452f4cac1099ca27313d2b
Author: Ian Romanick <ian.d.romanick at intel.com>
Date: Thu Mar 25 13:13:21 2021 -0700
nir/algebraic: Fix NaN-unsafe fcsel patterns
For example, the proof for this pattern
(('bcsel', ('flt', 'a at 32', 0), 'b at 32', 'c at 32'), ('fcsel_ge', a, c, b)),
would be
bcsel(a < 0, b, c)
bcsel(!(a < 0), c, b)
bcsel(a >= 0, c, b)
fcsel_ge(a, c, b)
However, !(a < 0) => (a >= 0) is well known to produce different
results if `a` is NaN.
Instead of that replacement, use this replacement:
bcsel(a < 0, b, c)
bcsel(-0 < -a, b, c)
bcsel(0 < -a, b, c)
fcsel_gt(-a, b, c)
This is NaN-safe and exact.
Reviewed-by: Alyssa Rosenzweig <alyssa at collabora.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand at collabora.com>
Fixes: 0f5b3c37c5d ("nir: Add opcodes for fused comp + csel and optimizations")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17048>
(cherry picked from commit a2a2fbc5101d6e6b5d18903c7a0bd84037dbdddc)
---
.pick_status.json | 2 +-
src/compiler/nir/nir_opt_algebraic.py | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index 9481b740c65..987e35235c9 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -319,7 +319,7 @@
"description": "nir/algebraic: Fix NaN-unsafe fcsel patterns",
"nominated": true,
"nomination_type": 1,
- "resolution": 0,
+ "resolution": 1,
"main_sha": null,
"because_sha": "0f5b3c37c5d757f6ffe994bae24071c0462bb13f"
},
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index d45adbfe147..4cc415131d5 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -1972,9 +1972,9 @@ optimizations.extend([
(('imul24', a, 0), (0)),
(('fcsel', ('slt', 0, a), b, c), ('fcsel_gt', a, b, c), "options->has_fused_comp_and_csel"),
- (('fcsel', ('slt', a, 0), b, c), ('fcsel_ge', a, c, b), "options->has_fused_comp_and_csel"),
+ (('fcsel', ('slt', a, 0), b, c), ('fcsel_gt', ('fneg', a), b, c), "options->has_fused_comp_and_csel"),
(('fcsel', ('sge', a, 0), b, c), ('fcsel_ge', a, b, c), "options->has_fused_comp_and_csel"),
- (('fcsel', ('sge', 0, a), b, c), ('fcsel_gt', a, c, b), "options->has_fused_comp_and_csel"),
+ (('fcsel', ('sge', 0, a), b, c), ('fcsel_ge', ('fneg', a), b, c), "options->has_fused_comp_and_csel"),
(('bcsel', ('ilt', 0, 'a at 32'), 'b at 32', 'c at 32'), ('i32csel_gt', a, b, c), "options->has_fused_comp_and_csel"),
(('bcsel', ('ilt', 'a at 32', 0), 'b at 32', 'c at 32'), ('i32csel_ge', a, c, b), "options->has_fused_comp_and_csel"),
@@ -1982,9 +1982,9 @@ optimizations.extend([
(('bcsel', ('ige', 0, 'a at 32'), 'b at 32', 'c at 32'), ('i32csel_gt', a, c, b), "options->has_fused_comp_and_csel"),
(('bcsel', ('flt', 0, 'a at 32'), 'b at 32', 'c at 32'), ('fcsel_gt', a, b, c), "options->has_fused_comp_and_csel"),
- (('bcsel', ('flt', 'a at 32', 0), 'b at 32', 'c at 32'), ('fcsel_ge', a, c, b), "options->has_fused_comp_and_csel"),
+ (('bcsel', ('flt', 'a at 32', 0), 'b at 32', 'c at 32'), ('fcsel_gt', ('fneg', a), b, c), "options->has_fused_comp_and_csel"),
(('bcsel', ('fge', 'a at 32', 0), 'b at 32', 'c at 32'), ('fcsel_ge', a, b, c), "options->has_fused_comp_and_csel"),
- (('bcsel', ('fge', 0, 'a at 32'), 'b at 32', 'c at 32'), ('fcsel_gt', a, c, b), "options->has_fused_comp_and_csel"),
+ (('bcsel', ('fge', 0, 'a at 32'), 'b at 32', 'c at 32'), ('fcsel_ge', ('fneg', a), b, c), "options->has_fused_comp_and_csel"),
])
More information about the mesa-commit
mailing list