Mesa (master): nir/algebraic: Add a couple optimizations for iabs and ishr

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Mar 15 01:50:35 UTC 2019


Module: Mesa
Branch: master
Commit: 2b76de9b5dd58c444c194d4c77ef9d9643ae5ca6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2b76de9b5dd58c444c194d4c77ef9d9643ae5ca6

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Sun Mar 10 10:06:56 2019 -0500

nir/algebraic: Add a couple optimizations for iabs and ishr

Shader-db results on Kaby Lake:

    total instructions in shared programs: 15225213 -> 15222365 (-0.02%)
    instructions in affected programs: 43524 -> 40676 (-6.54%)
    helped: 203
    HURT: 0

Lots of shaders in Shadow Warrior had this pattern along with Deus Ex,
Civ, Shadow of Mordor, and several others.

Reviewed-by: Kristian H. Kristensen <hoegsberg at chromium.org>

---

 src/compiler/nir/nir_opt_algebraic.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 5b2e7ee2405..3326bbef684 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -439,6 +439,12 @@ optimizations = [
    (('uge', '#a', ('umax', '#b', c)), ('iand', ('uge', a, b), ('uge', a, c))),
    (('uge', ('umin', '#a', b), '#c'), ('iand', ('uge', a, c), ('uge', b, c))),
 
+   # Thanks to sign extension, the ishr(a, b) is negative if and only if a is
+   # negative.
+   (('bcsel', ('ilt', a, 0), ('ineg', ('ishr', a, b)), ('ishr', a, b)),
+    ('iabs', ('ishr', a, b))),
+   (('iabs', ('ishr', ('iabs', a), b)), ('ishr', ('iabs', a), b)),
+
    (('fabs', ('slt', a, b)), ('slt', a, b)),
    (('fabs', ('sge', a, b)), ('sge', a, b)),
    (('fabs', ('seq', a, b)), ('seq', a, b)),




More information about the mesa-commit mailing list