[Mesa-dev] [PATCH 3/3] nir: Add some more optimizations for handling constants in bcsel

Jason Ekstrand jason at jlekstrand.net
Fri Jan 23 22:04:41 PST 2015


shader-db results based on my scalarizing patches:

total instructions in shared programs: 6077319 -> 6076895 (-0.01%)
instructions in affected programs:     63509 -> 63085 (-0.67%)
helped:                                306
HURT:                                  0
GAINED:                                0
LOST:                                  0
---
 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 9c62b28..481ef58 100644
--- a/src/glsl/nir/nir_opt_algebraic.py
+++ b/src/glsl/nir/nir_opt_algebraic.py
@@ -116,4 +116,17 @@ optimizations = [
    (('feq', ('fadd', a, b), 0.0), ('feq', a, ('fneg', b))),
 ]
 
+# Add optimizations to handle the case where the result of a ternary is
+# compared to a constant.  This way we can take things like
+for op in ['flt', 'fge', 'feq', 'fne',
+           'ilt', 'ige', 'ieq', 'ine', 'ult', 'uge']:
+   optimizations += [
+      ((op, ('bcsel', 'a', '#b', '#c'), '#d'),
+       ('bcsel', 'a', (op, 'b', 'd'), (op, 'c', 'd'))),
+      ((op, '#d', ('bcsel', a, '#b', '#c')),
+       ('bcsel', 'a', (op, 'd', 'b'), (op, 'd', 'c'))),
+      (('bcsel', (op, 'a', 'b'), True, False), (op, 'a', 'b')),
+      (('bcsel', (op, 'a', 'b'), False, True), ('inot', (op, 'a', 'b'))),
+   ]
+
 print nir_algebraic.AlgebraicPass("nir_opt_algebraic", optimizations).render()
-- 
2.2.1



More information about the mesa-dev mailing list