[Mesa-dev] [PATCH 06/10] nir: Add a bunch of algebraic optimizations on logic/bit operations.
Kenneth Graunke
kenneth at whitecape.org
Thu Jan 22 03:41:27 PST 2015
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.
total NIR instructions in shared programs: 2023511 -> 2020814 (-0.13%)
NIR instructions in affected programs: 149634 -> 146937 (-1.80%)
helped: 1032
i965 already cleans these up, so the final results aren't impressive:
total i965 instructions in shared programs: 6035392 -> 6035397 (0.00%)
i965 instructions in affected programs: 764 -> 769 (0.65%)
HURT: 3
However, improving the result of the NIR compile is worth doing.
Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
src/glsl/nir/nir_opt_algebraic.py | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py
index 169bb41..cf16b19 100644
--- a/src/glsl/nir/nir_opt_algebraic.py
+++ b/src/glsl/nir/nir_opt_algebraic.py
@@ -68,6 +68,22 @@ 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, a), a),
+ (('fand', a, 0.0), 0.0),
+ (('iand', a, a), a),
+ (('iand', a, 0), 0),
+ (('for', a, a), a),
+ (('for', a, 0.0), a),
+ (('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))),
]
--
2.2.2
More information about the mesa-dev
mailing list