summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_opt_algebraic.py
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2019-03-10 10:06:56 -0500
committerJason Ekstrand <[email protected]>2019-03-15 01:02:19 +0000
commit2b76de9b5dd58c444c194d4c77ef9d9643ae5ca6 (patch)
tree05a96c9a8ec208860e57d5b140e4960311aec4bc /src/compiler/nir/nir_opt_algebraic.py
parent0803bef00675ddd90ca9365b733b222dbb58c373 (diff)
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 <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_opt_algebraic.py')
-rw-r--r--src/compiler/nir/nir_opt_algebraic.py6
1 files changed, 6 insertions, 0 deletions
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)),