summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>2020-08-31 16:08:55 +0200
committerEric Engestrom <eric@engestrom.ch>2020-09-02 21:50:47 +0200
commit20c437092933f834168dec08d492e12ea17c2a7f (patch)
treed01c4c726e26776e3800f70be184a095e9f6f29d
parent9e68c391094569c8b16453c84bb4f1f270dec5f3 (diff)
nir/algebraic: mark some optimizations with fsat(NaN) as inexact
If a is Nan, fsat(NaN) is expected to be 0 and some optimizations should be marked as inexact. Fixes a GPU hang with Death Stranding and RADV/ACO (RADV/LLVM isn't affected because it lowers fsat). No fossils-db change. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3368 Cc: mesa-stable Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> Reviewed-by: Rhys Perry <pendingchaos02@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6519> (cherry picked from commit bc123c396a99b2f6ff845792374d6a8d5de5d15e)
-rw-r--r--.pick_status.json2
-rw-r--r--src/compiler/nir/nir_opt_algebraic.py12
2 files changed, 10 insertions, 4 deletions
diff --git a/.pick_status.json b/.pick_status.json
index 164afa4274d..55b04bb680a 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -814,7 +814,7 @@
"description": "nir/algebraic: mark some optimizations with fsat(NaN) as inexact",
"nominated": true,
"nomination_type": 0,
- "resolution": 0,
+ "resolution": 1,
"master_sha": null,
"because_sha": null
},
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 8f45b99060b..92bea7a4510 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -327,10 +327,14 @@ optimizations.extend([
(('fne', ('fneg', a), -1.0), ('fne', 1.0, a)),
(('feq', -1.0, ('fneg', a)), ('feq', a, 1.0)),
- (('flt', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('flt', a, b)),
+ # flt(fsat(a), b > 0 && b < 1) is inexact if a is NaN (fsat(NaN) is 0)
+ # because it returns True while flt(a, b) always returns False.
+ (('~flt', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('flt', a, b)),
(('flt', '#b(is_gt_0_and_lt_1)', ('fsat(is_used_once)', a)), ('flt', b, a)),
(('fge', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fge', a, b)),
- (('fge', '#b(is_gt_0_and_lt_1)', ('fsat(is_used_once)', a)), ('fge', b, a)),
+ # fge(b > 0 && b < 1, fsat(a)) is inexact if a is NaN (fsat(NaN) is 0)
+ # because it returns True while fge(b, a) always returns False.
+ (('~fge', '#b(is_gt_0_and_lt_1)', ('fsat(is_used_once)', a)), ('fge', b, a)),
(('feq', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('feq', a, b)),
(('fne', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fne', a, b)),
@@ -1767,7 +1771,9 @@ late_optimizations = [
(('fne', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fne', a, b)),
(('fge', ('fsat(is_used_once)', a), 1.0), ('fge', a, 1.0)),
- (('flt', ('fsat(is_used_once)', a), 1.0), ('flt', a, 1.0)),
+ # flt(fsat(a), 1.0) is inexact because it returns True if a is NaN
+ # (fsat(NaN) is 0), while flt(a, 1.0) always returns FALSE.
+ (('~flt', ('fsat(is_used_once)', a), 1.0), ('flt', a, 1.0)),
(('~fge', ('fmin(is_used_once)', ('fadd(is_used_once)', a, b), ('fadd', c, d)), 0.0), ('iand', ('fge', a, ('fneg', b)), ('fge', c, ('fneg', d)))),