Mesa (master): nir: Add a bunch of algebraic optimizations on logic/ bit operations.

Kenneth Graunke kwg at kemper.freedesktop.org
Fri Jan 23 22:55:23 UTC 2015


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

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Mon Jan 19 14:57:38 2015 -0800

nir: Add a bunch of algebraic optimizations on logic/bit operations.

Matt and I noticed a bunch of "val <- ior a a" operations in a shader,
so we decided to add an algebraic optimization for that.  While there,
I decided to add a bunch more of them.

v2: Delete bogus fand/for optimizations (caught by Jason).

total NIR instructions in shared programs: 2023511 -> 2020814 (-0.13%)
NIR instructions in affected programs:     149634 -> 146937 (-1.80%)
helped:                                    1032

total i965 instructions in shared programs: 6035392 -> 6035397 (0.00%)
i965 instructions in affected programs:     537 -> 542 (0.93%)
HURT:                                       2

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Jason Ekstrand <jason.ekstrand at intel.com>
Reviewed-by: Matt Turner <mattst88 at gmail.com>

---

 src/glsl/nir/nir_opt_algebraic.py |   13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py
index 169bb41..53fe4a0 100644
--- a/src/glsl/nir/nir_opt_algebraic.py
+++ b/src/glsl/nir/nir_opt_algebraic.py
@@ -68,6 +68,19 @@ optimizations = [
    (('fadd', ('fmul', a, b), c), ('ffma', a, b, c)),
    (('fge', ('fneg', ('fabs', a)), 0.0), ('feq', a, 0.0)),
    (('fmin', ('fmax', a, 1.0), 0.0), ('fsat', a)),
+   # Logical and bit operations
+   (('fand', a, 0.0), 0.0),
+   (('iand', a, a), a),
+   (('iand', a, 0), 0),
+   (('ior', a, a), a),
+   (('ior', a, 0), a),
+   (('fxor', a, a), 0.0),
+   (('ixor', a, a), 0),
+   (('inot', ('inot', a)), a),
+   # DeMorgan's Laws
+   (('iand', ('inot', a), ('inot', b)), ('inot', ('ior',  a, b))),
+   (('ior',  ('inot', a), ('inot', b)), ('inot', ('iand', a, b))),
+
 # This one may not be exact
    (('feq', ('fadd', a, b), 0.0), ('feq', a, ('fneg', b))),
 ]




More information about the mesa-commit mailing list