Mesa (staging/21.0): nir/algebraic: mark more optimization with fsat(NaN) as inexact

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jan 28 18:46:54 UTC 2021


Module: Mesa
Branch: staging/21.0
Commit: de78b1c88d5a36ee5d78e56870b0e459b61a9c54
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=de78b1c88d5a36ee5d78e56870b0e459b61a9c54

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Tue Jan 26 14:25:32 2021 +0100

nir/algebraic: mark more optimization with fsat(NaN) as inexact

These optimizations are duplicated from the main optimization table
to the late one... And I missed some in the original fix.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3368
Fixes: bc123c396a9 ("nir/algebraic: mark some optimizations with fsat(NaN) as inexact")
Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8716>
(cherry picked from commit 4c3ad4d06588dcc8f5c4d9e27c746055a013f358)

---

 .pick_status.json                     |  2 +-
 src/compiler/nir/nir_opt_algebraic.py | 17 +++++++++++++----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index c93eb6eb214..8e1ef0ab613 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -445,7 +445,7 @@
         "description": "nir/algebraic: mark more optimization with fsat(NaN) as inexact",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "master_sha": null,
         "because_sha": "bc123c396a99b2f6ff845792374d6a8d5de5d15e"
     },
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index a1fe299db45..35a51aa4806 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -358,8 +358,12 @@ optimizations.extend([
    (('fneu', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fneu', 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)),
-   (('fge', 0.0, ('fsat(is_used_once)', a)), ('fge', 0.0, a)),
+   # 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(0.0, fsat(a)) is inexact because it returns True if a is NaN
+   # (fsat(NaN) is 0), while fge(0.0, a) always returns FALSE.
+   (('~fge', 0.0, ('fsat(is_used_once)', a)), ('fge', 0.0, a)),
    (('flt', 0.0, ('fsat(is_used_once)', a)), ('flt', 0.0, a)),
 
    # 0.0 >= b2f(a)
@@ -2120,10 +2124,15 @@ late_optimizations = [
    # new patterns like these.  The patterns that compare with zero are removed
    # because they are unlikely to be created in by anything in
    # late_optimizations.
-   (('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)),
    (('fneu', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fneu', a, b)),
 



More information about the mesa-commit mailing list