<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 29, 2015 at 12:50 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">total instructions in shared programs: 8026469 -> 8026343 (-0.00%)<br>
instructions in affected programs:     28541 -> 28415 (-0.44%)<br>
helped:                                101<br>
HURT:                                  76<br></blockquote><div><br></div><div>These numbers are bogus too.  The real ones look good for NIR but not for FS.  I'm looking into that.<br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
 src/glsl/nir/nir_opt_algebraic.py | 26 ++++++++++++++++++++++++++<br>
 1 file changed, 26 insertions(+)<br>
<br>
diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py<br>
index e3b309c..4e1beb4 100644<br>
--- a/src/glsl/nir/nir_opt_algebraic.py<br>
+++ b/src/glsl/nir/nir_opt_algebraic.py<br>
@@ -122,9 +122,35 @@ optimizations = [<br>
    (('ieq', 'a@bool', 0), ('inot', 'a')),<br>
    (('bcsel', 'a@bool', True, False), 'a'),<br>
    (('bcsel', 'a@bool', False, True), ('inot', 'a')),<br>
+   (('bcsel', True, b, c), b),<br>
+   (('bcsel', False, b, c), c),<br>
+   # The result of this should be hit by constant propagation and, in the<br>
+   # next round of opt_algebraic, get picked up by one of the above two.<br>
+   (('bcsel', '#a', b, c), ('bcsel', ('ine', 'a', 0), b, c)),<br>
<br>
 # This one may not be exact<br>
    (('feq', ('fadd', a, b), 0.0), ('feq', a, ('fneg', b))),<br>
 ]<br>
<br>
+# Add optimizations to handle the case where the result of a ternary is<br>
+# compared to a constant.  This way we can take things like<br>
+#<br>
+# (a ? 0 : 1) > 0<br>
+#<br>
+# and turn it into<br>
+#<br>
+# a ? (0 > 0) : (1 > 0)<br>
+#<br>
+# which constant folding will eat for lunch.  The resulting ternary will<br>
+# further get cleaned up by the boolean reductions above ane we will be<br>
+# left with just the original variable "a".<br>
+for op in ['flt', 'fge', 'feq', 'fne',<br>
+           'ilt', 'ige', 'ieq', 'ine', 'ult', 'uge']:<br>
+   optimizations += [<br>
+      ((op, ('bcsel', 'a', '#b', '#c'), '#d'),<br>
+       ('bcsel', 'a', (op, 'b', 'd'), (op, 'c', 'd'))),<br>
+      ((op, '#d', ('bcsel', a, '#b', '#c')),<br>
+       ('bcsel', 'a', (op, 'd', 'b'), (op, 'd', 'c'))),<br>
+   ]<br>
+<br>
 print nir_algebraic.AlgebraicPass("nir_opt_algebraic", optimizations).render()<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.2.2<br>
<br>
</font></span></blockquote></div><br></div></div>