<p dir="ltr"></p>
<p dir="ltr">On Aug 10, 2016 1:02 AM, "Erik Faye-Lund" <<a href="mailto:kusmabite@gmail.com">kusmabite@gmail.com</a>> wrote:<br>
><br>
> On Wed, Aug 10, 2016 at 4:30 AM, Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>> wrote:<br>
> > On Haswell (GL 3.3):<br>
> ><br>
> > total instructions in shared programs: 6208759 -> 6203860 (-0.08%)<br>
> > instructions in affected programs: 856541 -> 851642 (-0.57%)<br>
> > helped: 3157<br>
> > HURT: 113<br>
> > LOST: 7<br>
> > GAINED: 15<br>
> ><br>
> > On Broadwell (GL 4.4):<br>
> ><br>
> > total instructions in shared programs: 11637854 -> 11632016 (-0.05%)<br>
> > instructions in affected programs: 1055693 -> 1049855 (-0.55%)<br>
> > helped: 3900<br>
> > HURT: 176<br>
> > LOST: 1<br>
> > GAINED: 18<br>
> ><br>
> > Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
> > ---<br>
> > src/compiler/nir/nir_opt_algebraic.py | 4 ++++<br>
> > 1 file changed, 4 insertions(+)<br>
> ><br>
> > diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py<br>
> > index 1cf614c..4e9896f 100644<br>
> > --- a/src/compiler/nir/nir_opt_algebraic.py<br>
> > +++ b/src/compiler/nir/nir_opt_algebraic.py<br>
> > @@ -251,6 +251,10 @@ optimizations = [<br>
> > (('ieq', 'a@bool', False), ('inot', 'a')),<br>
> > (('bcsel', a, True, False), ('ine', a, 0)),<br>
> > (('bcsel', a, False, True), ('ieq', a, 0)),<br>
> > + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))),<br>
> > + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))),<br>
> > + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0)))),<br>
> > + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0)))),<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>
><br>
> Same as the previous patch, this smells like intel-isms. Hardware that<br>
> has native bcsel with support for two inline immediates will do better<br>
> without.</p>
<p dir="ltr">Why? If you're back-end handles b2f *worse* then bcsel of two components, then it's broken. Also, we have a lot of optimization in NIR to help cut through "fake booleans" where shaders use 0.0 and 1.0 and math operations instead of actual booleans. Recognising hand-coded b2f suddenly enables more of these optimization paths to run on the shader. That 0.57% isn't all just immediates being removed.</p>