Re: [Mesa-dev] [PATCH 2/6] nir: Turn bcsel of +/- 1.0 and 0.0 into b2f sequences.
On 08/10/2016 12:50 PM, Eric Anholt wrote: > Connor Abbott writes: > >> On Wed, Aug 10, 2016 at 1:53 PM, Eric Anholt wrote: >>> Kenneth Graunke writes: >>> On Haswell (GL 3.3): total instructions in shared programs: 6208759 -> 6203860 (-0.08%) instructions in affected programs: 856541 -> 851642 (-0.57%) helped: 3157 HURT: 113 LOST: 7 GAINED: 15 On Broadwell (GL 4.4): total instructions in shared programs: 11637854 -> 11632016 (-0.05%) instructions in affected programs: 1055693 -> 1049855 (-0.55%) helped: 3900 HURT: 176 LOST: 1 GAINED: 18 Signed-off-by: Kenneth Graunke --- src/compiler/nir/nir_opt_algebraic.py | 4 1 file changed, 4 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 1cf614c..4e9896f 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -251,6 +251,10 @@ optimizations = [ (('ieq', 'a@bool', False), ('inot', 'a')), (('bcsel', a, True, False), ('ine', a, 0)), (('bcsel', a, False, True), ('ieq', a, 0)), + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))), + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))), + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0, + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0, >>> >>> Isn't bcsel's first arg guaranteed to be 0 or ~0? I thought that was >>> how nir's bcsel (and b2f) worked. If not, it would be good to see this >>> documented. >> >> Yes, any ALU operation that takes a boolean input can expect it to be >> 0 or ~0. If that isn't true, then something else in the compiler has >> messed up. So I think we can replace 'a != 0' with 'a' and 'a == 0' >> with '!a'. > > Yeah. So, I like the contents of this series a lot, but it would be > nice to see some of the @bool annotations dropped. Right... because ('b2f', 'a@bool') is redundant. I agree. > ___ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-dev signature.asc Description: OpenPGP digital signature ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/6] nir: Turn bcsel of +/- 1.0 and 0.0 into b2f sequences.
On Wed, Aug 10, 2016 at 2:24 PM, Kenneth Graunke wrote: > On Wednesday, August 10, 2016 10:02:12 AM PDT Erik Faye-Lund wrote: >> On Wed, Aug 10, 2016 at 4:30 AM, Kenneth Graunke >> wrote: >> > On Haswell (GL 3.3): >> > >> > total instructions in shared programs: 6208759 -> 6203860 (-0.08%) >> > instructions in affected programs: 856541 -> 851642 (-0.57%) >> > helped: 3157 >> > HURT: 113 >> > LOST: 7 >> > GAINED: 15 >> > >> > On Broadwell (GL 4.4): >> > >> > total instructions in shared programs: 11637854 -> 11632016 (-0.05%) >> > instructions in affected programs: 1055693 -> 1049855 (-0.55%) >> > helped: 3900 >> > HURT: 176 >> > LOST: 1 >> > GAINED: 18 >> > >> > Signed-off-by: Kenneth Graunke >> > --- >> > src/compiler/nir/nir_opt_algebraic.py | 4 >> > 1 file changed, 4 insertions(+) >> > >> > diff --git a/src/compiler/nir/nir_opt_algebraic.py >> > b/src/compiler/nir/nir_opt_algebraic.py >> > index 1cf614c..4e9896f 100644 >> > --- a/src/compiler/nir/nir_opt_algebraic.py >> > +++ b/src/compiler/nir/nir_opt_algebraic.py >> > @@ -251,6 +251,10 @@ optimizations = [ >> > (('ieq', 'a@bool', False), ('inot', 'a')), >> > (('bcsel', a, True, False), ('ine', a, 0)), >> > (('bcsel', a, False, True), ('ieq', a, 0)), >> > + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))), >> > + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))), >> > + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0, >> > + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0, >> > (('bcsel', True, b, c), b), >> > (('bcsel', False, b, c), c), >> > # The result of this should be hit by constant propagation and, in the >> >> Same as the previous patch, this smells like intel-isms. Hardware that >> has native bcsel with support for two inline immediates will do better >> without. > > It definitely feels a little strange replacing a single bcsel with > a fneg/b2f/ine, as that's three operations instead of one. > > I expect the ine to go away - assuming 'a' is a properly formatted > boolean (0 or 0x), "ine a 0" will just become 'a'. ieq would > turn into inot. I made the point in another place in this thread, but you don't have to assume -- things that take booleans as input should only ever get 0 or ~0. Anything else would be a bug in the compiler. Now that I have a little more free time before school starts, I've been thinking about making booleans have a bit-width of 1 (i.e. making them logical) and then only lowering to their concrete representation very late, if at all. That would keep this confusion from happening, in addition to bringing a lot of other benefits, and it should be a lot easier now that we have bit widths in NIR. > If the boolean was a comparison, the inot could be > folded in - i.e. inot(flt(a,b)) -> fge(a,b). Or, some GPUs can handle > boolean negation as a source modifier, so it might be free there too. > > Floating point negation can usually be done as a source modifier. > > For reference, here's a shader snippet from Goat Simulator which > prompted me to write this optimization: > > const vec4 LocalConst1 = vec4(0.25, -0.25, 0.00, 1.00); > > void main() > { > ... > InstrHelpTemp.r = ( ( Temporary1.r >= 0.0 ) ? LocalConst1.b : LocalConst1.a ); > ... > } > > which could be turned into > > InstrHelpTemp.r = float(Temporary1.r < 0.0); > > which seems arguably better, regardless of hardware. > > ___ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-dev > ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/6] nir: Turn bcsel of +/- 1.0 and 0.0 into b2f sequences.
Connor Abbott writes: > On Wed, Aug 10, 2016 at 1:53 PM, Eric Anholt wrote: >> Kenneth Graunke writes: >> >>> On Haswell (GL 3.3): >>> >>> total instructions in shared programs: 6208759 -> 6203860 (-0.08%) >>> instructions in affected programs: 856541 -> 851642 (-0.57%) >>> helped: 3157 >>> HURT: 113 >>> LOST: 7 >>> GAINED: 15 >>> >>> On Broadwell (GL 4.4): >>> >>> total instructions in shared programs: 11637854 -> 11632016 (-0.05%) >>> instructions in affected programs: 1055693 -> 1049855 (-0.55%) >>> helped: 3900 >>> HURT: 176 >>> LOST: 1 >>> GAINED: 18 >>> >>> Signed-off-by: Kenneth Graunke >>> --- >>> src/compiler/nir/nir_opt_algebraic.py | 4 >>> 1 file changed, 4 insertions(+) >>> >>> diff --git a/src/compiler/nir/nir_opt_algebraic.py >>> b/src/compiler/nir/nir_opt_algebraic.py >>> index 1cf614c..4e9896f 100644 >>> --- a/src/compiler/nir/nir_opt_algebraic.py >>> +++ b/src/compiler/nir/nir_opt_algebraic.py >>> @@ -251,6 +251,10 @@ optimizations = [ >>> (('ieq', 'a@bool', False), ('inot', 'a')), >>> (('bcsel', a, True, False), ('ine', a, 0)), >>> (('bcsel', a, False, True), ('ieq', a, 0)), >>> + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))), >>> + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))), >>> + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0, >>> + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0, >> >> Isn't bcsel's first arg guaranteed to be 0 or ~0? I thought that was >> how nir's bcsel (and b2f) worked. If not, it would be good to see this >> documented. > > Yes, any ALU operation that takes a boolean input can expect it to be > 0 or ~0. If that isn't true, then something else in the compiler has > messed up. So I think we can replace 'a != 0' with 'a' and 'a == 0' > with '!a'. Yeah. So, I like the contents of this series a lot, but it would be nice to see some of the @bool annotations dropped. signature.asc Description: PGP signature ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/6] nir: Turn bcsel of +/- 1.0 and 0.0 into b2f sequences.
On 08/10/2016 11:24 AM, Kenneth Graunke wrote: > On Wednesday, August 10, 2016 10:02:12 AM PDT Erik Faye-Lund wrote: >> On Wed, Aug 10, 2016 at 4:30 AM, Kenneth Graunke >> wrote: >>> On Haswell (GL 3.3): >>> >>> total instructions in shared programs: 6208759 -> 6203860 (-0.08%) >>> instructions in affected programs: 856541 -> 851642 (-0.57%) >>> helped: 3157 >>> HURT: 113 >>> LOST: 7 >>> GAINED: 15 >>> >>> On Broadwell (GL 4.4): >>> >>> total instructions in shared programs: 11637854 -> 11632016 (-0.05%) >>> instructions in affected programs: 1055693 -> 1049855 (-0.55%) >>> helped: 3900 >>> HURT: 176 >>> LOST: 1 >>> GAINED: 18 >>> >>> Signed-off-by: Kenneth Graunke >>> --- >>> src/compiler/nir/nir_opt_algebraic.py | 4 >>> 1 file changed, 4 insertions(+) >>> >>> diff --git a/src/compiler/nir/nir_opt_algebraic.py >>> b/src/compiler/nir/nir_opt_algebraic.py >>> index 1cf614c..4e9896f 100644 >>> --- a/src/compiler/nir/nir_opt_algebraic.py >>> +++ b/src/compiler/nir/nir_opt_algebraic.py >>> @@ -251,6 +251,10 @@ optimizations = [ >>> (('ieq', 'a@bool', False), ('inot', 'a')), >>> (('bcsel', a, True, False), ('ine', a, 0)), >>> (('bcsel', a, False, True), ('ieq', a, 0)), >>> + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))), >>> + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))), >>> + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0, >>> + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0, >>> (('bcsel', True, b, c), b), >>> (('bcsel', False, b, c), c), >>> # The result of this should be hit by constant propagation and, in the >> >> Same as the previous patch, this smells like intel-isms. Hardware that >> has native bcsel with support for two inline immediates will do better >> without. > > It definitely feels a little strange replacing a single bcsel with > a fneg/b2f/ine, as that's three operations instead of one. > > I expect the ine to go away - assuming 'a' is a properly formatted > boolean (0 or 0x), "ine a 0" will just become 'a'. ieq would > turn into inot. If the boolean was a comparison, the inot could be > folded in - i.e. inot(flt(a,b)) -> fge(a,b). Or, some GPUs can handle > boolean negation as a source modifier, so it might be free there too. > > Floating point negation can usually be done as a source modifier. > > For reference, here's a shader snippet from Goat Simulator which > prompted me to write this optimization: > > const vec4 LocalConst1 = vec4(0.25, -0.25, 0.00, 1.00); > > void main() > { > ... > InstrHelpTemp.r = ( ( Temporary1.r >= 0.0 ) ? LocalConst1.b : LocalConst1.a ); > ... > } > > which could be turned into > > InstrHelpTemp.r = float(Temporary1.r < 0.0); > > which seems arguably better, regardless of hardware. Yeah... I remember looking at that very shader. I seem to recall that InstrHelpTemp.r is then compared with 0.0 a little later to generate another Boolean value. :) > ___ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-dev > signature.asc Description: OpenPGP digital signature ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/6] nir: Turn bcsel of +/- 1.0 and 0.0 into b2f sequences.
On Wednesday, August 10, 2016 10:02:12 AM PDT Erik Faye-Lund wrote: > On Wed, Aug 10, 2016 at 4:30 AM, Kenneth Graunke > wrote: > > On Haswell (GL 3.3): > > > > total instructions in shared programs: 6208759 -> 6203860 (-0.08%) > > instructions in affected programs: 856541 -> 851642 (-0.57%) > > helped: 3157 > > HURT: 113 > > LOST: 7 > > GAINED: 15 > > > > On Broadwell (GL 4.4): > > > > total instructions in shared programs: 11637854 -> 11632016 (-0.05%) > > instructions in affected programs: 1055693 -> 1049855 (-0.55%) > > helped: 3900 > > HURT: 176 > > LOST: 1 > > GAINED: 18 > > > > Signed-off-by: Kenneth Graunke > > --- > > src/compiler/nir/nir_opt_algebraic.py | 4 > > 1 file changed, 4 insertions(+) > > > > diff --git a/src/compiler/nir/nir_opt_algebraic.py > > b/src/compiler/nir/nir_opt_algebraic.py > > index 1cf614c..4e9896f 100644 > > --- a/src/compiler/nir/nir_opt_algebraic.py > > +++ b/src/compiler/nir/nir_opt_algebraic.py > > @@ -251,6 +251,10 @@ optimizations = [ > > (('ieq', 'a@bool', False), ('inot', 'a')), > > (('bcsel', a, True, False), ('ine', a, 0)), > > (('bcsel', a, False, True), ('ieq', a, 0)), > > + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))), > > + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))), > > + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0, > > + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0, > > (('bcsel', True, b, c), b), > > (('bcsel', False, b, c), c), > > # The result of this should be hit by constant propagation and, in the > > Same as the previous patch, this smells like intel-isms. Hardware that > has native bcsel with support for two inline immediates will do better > without. It definitely feels a little strange replacing a single bcsel with a fneg/b2f/ine, as that's three operations instead of one. I expect the ine to go away - assuming 'a' is a properly formatted boolean (0 or 0x), "ine a 0" will just become 'a'. ieq would turn into inot. If the boolean was a comparison, the inot could be folded in - i.e. inot(flt(a,b)) -> fge(a,b). Or, some GPUs can handle boolean negation as a source modifier, so it might be free there too. Floating point negation can usually be done as a source modifier. For reference, here's a shader snippet from Goat Simulator which prompted me to write this optimization: const vec4 LocalConst1 = vec4(0.25, -0.25, 0.00, 1.00); void main() { ... InstrHelpTemp.r = ( ( Temporary1.r >= 0.0 ) ? LocalConst1.b : LocalConst1.a ); ... } which could be turned into InstrHelpTemp.r = float(Temporary1.r < 0.0); which seems arguably better, regardless of hardware. signature.asc Description: This is a digitally signed message part. ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/6] nir: Turn bcsel of +/- 1.0 and 0.0 into b2f sequences.
On Wed, Aug 10, 2016 at 1:53 PM, Eric Anholt wrote: > Kenneth Graunke writes: > >> On Haswell (GL 3.3): >> >> total instructions in shared programs: 6208759 -> 6203860 (-0.08%) >> instructions in affected programs: 856541 -> 851642 (-0.57%) >> helped: 3157 >> HURT: 113 >> LOST: 7 >> GAINED: 15 >> >> On Broadwell (GL 4.4): >> >> total instructions in shared programs: 11637854 -> 11632016 (-0.05%) >> instructions in affected programs: 1055693 -> 1049855 (-0.55%) >> helped: 3900 >> HURT: 176 >> LOST: 1 >> GAINED: 18 >> >> Signed-off-by: Kenneth Graunke >> --- >> src/compiler/nir/nir_opt_algebraic.py | 4 >> 1 file changed, 4 insertions(+) >> >> diff --git a/src/compiler/nir/nir_opt_algebraic.py >> b/src/compiler/nir/nir_opt_algebraic.py >> index 1cf614c..4e9896f 100644 >> --- a/src/compiler/nir/nir_opt_algebraic.py >> +++ b/src/compiler/nir/nir_opt_algebraic.py >> @@ -251,6 +251,10 @@ optimizations = [ >> (('ieq', 'a@bool', False), ('inot', 'a')), >> (('bcsel', a, True, False), ('ine', a, 0)), >> (('bcsel', a, False, True), ('ieq', a, 0)), >> + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))), >> + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))), >> + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0, >> + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0, > > Isn't bcsel's first arg guaranteed to be 0 or ~0? I thought that was > how nir's bcsel (and b2f) worked. If not, it would be good to see this > documented. Yes, any ALU operation that takes a boolean input can expect it to be 0 or ~0. If that isn't true, then something else in the compiler has messed up. So I think we can replace 'a != 0' with 'a' and 'a == 0' with '!a'. > > ___ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-dev > ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/6] nir: Turn bcsel of +/- 1.0 and 0.0 into b2f sequences.
On 08/09/2016 07:30 PM, Kenneth Graunke wrote: > On Haswell (GL 3.3): > > total instructions in shared programs: 6208759 -> 6203860 (-0.08%) > instructions in affected programs: 856541 -> 851642 (-0.57%) > helped: 3157 > HURT: 113 > LOST: 7 > GAINED: 15 > > On Broadwell (GL 4.4): > > total instructions in shared programs: 11637854 -> 11632016 (-0.05%) > instructions in affected programs: 1055693 -> 1049855 (-0.55%) > helped: 3900 > HURT: 176 > LOST: 1 > GAINED: 18 > > Signed-off-by: Kenneth Graunke > --- > src/compiler/nir/nir_opt_algebraic.py | 4 > 1 file changed, 4 insertions(+) > > diff --git a/src/compiler/nir/nir_opt_algebraic.py > b/src/compiler/nir/nir_opt_algebraic.py > index 1cf614c..4e9896f 100644 > --- a/src/compiler/nir/nir_opt_algebraic.py > +++ b/src/compiler/nir/nir_opt_algebraic.py > @@ -251,6 +251,10 @@ optimizations = [ > (('ieq', 'a@bool', False), ('inot', 'a')), > (('bcsel', a, True, False), ('ine', a, 0)), > (('bcsel', a, False, True), ('ieq', a, 0)), > + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))), > + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))), > + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0, > + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0, One of the other things I was experimenting with, that had mixed results, was rearranging larger sequences like x * bcsel(b, 1.0, 0.0). There were a few different ways to handle it, and the optimal way was dependent on the way the Boolean value was generated and on the way the result was used. This dovetailed into my work in removing spurious b2f (and f2i) expressions. > (('bcsel', True, b, c), b), > (('bcsel', False, b, c), c), > # The result of this should be hit by constant propagation and, in the > ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/6] nir: Turn bcsel of +/- 1.0 and 0.0 into b2f sequences.
Kenneth Graunke writes: > On Haswell (GL 3.3): > > total instructions in shared programs: 6208759 -> 6203860 (-0.08%) > instructions in affected programs: 856541 -> 851642 (-0.57%) > helped: 3157 > HURT: 113 > LOST: 7 > GAINED: 15 > > On Broadwell (GL 4.4): > > total instructions in shared programs: 11637854 -> 11632016 (-0.05%) > instructions in affected programs: 1055693 -> 1049855 (-0.55%) > helped: 3900 > HURT: 176 > LOST: 1 > GAINED: 18 > > Signed-off-by: Kenneth Graunke > --- > src/compiler/nir/nir_opt_algebraic.py | 4 > 1 file changed, 4 insertions(+) > > diff --git a/src/compiler/nir/nir_opt_algebraic.py > b/src/compiler/nir/nir_opt_algebraic.py > index 1cf614c..4e9896f 100644 > --- a/src/compiler/nir/nir_opt_algebraic.py > +++ b/src/compiler/nir/nir_opt_algebraic.py > @@ -251,6 +251,10 @@ optimizations = [ > (('ieq', 'a@bool', False), ('inot', 'a')), > (('bcsel', a, True, False), ('ine', a, 0)), > (('bcsel', a, False, True), ('ieq', a, 0)), > + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))), > + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))), > + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0, > + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0, Isn't bcsel's first arg guaranteed to be 0 or ~0? I thought that was how nir's bcsel (and b2f) worked. If not, it would be good to see this documented. signature.asc Description: PGP signature ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/6] nir: Turn bcsel of +/- 1.0 and 0.0 into b2f sequences.
On Wed, Aug 10, 2016 at 5:48 PM, Jason Ekstrand wrote: > On Aug 10, 2016 1:02 AM, "Erik Faye-Lund" wrote: >> >> On Wed, Aug 10, 2016 at 4:30 AM, Kenneth Graunke >> wrote: >> > On Haswell (GL 3.3): >> > >> > total instructions in shared programs: 6208759 -> 6203860 (-0.08%) >> > instructions in affected programs: 856541 -> 851642 (-0.57%) >> > helped: 3157 >> > HURT: 113 >> > LOST: 7 >> > GAINED: 15 >> > >> > On Broadwell (GL 4.4): >> > >> > total instructions in shared programs: 11637854 -> 11632016 (-0.05%) >> > instructions in affected programs: 1055693 -> 1049855 (-0.55%) >> > helped: 3900 >> > HURT: 176 >> > LOST: 1 >> > GAINED: 18 >> > >> > Signed-off-by: Kenneth Graunke >> > --- >> > src/compiler/nir/nir_opt_algebraic.py | 4 >> > 1 file changed, 4 insertions(+) >> > >> > diff --git a/src/compiler/nir/nir_opt_algebraic.py >> > b/src/compiler/nir/nir_opt_algebraic.py >> > index 1cf614c..4e9896f 100644 >> > --- a/src/compiler/nir/nir_opt_algebraic.py >> > +++ b/src/compiler/nir/nir_opt_algebraic.py >> > @@ -251,6 +251,10 @@ optimizations = [ >> > (('ieq', 'a@bool', False), ('inot', 'a')), >> > (('bcsel', a, True, False), ('ine', a, 0)), >> > (('bcsel', a, False, True), ('ieq', a, 0)), >> > + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))), >> > + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))), >> > + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0, >> > + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0, >> > (('bcsel', True, b, c), b), >> > (('bcsel', False, b, c), c), >> > # The result of this should be hit by constant propagation and, in >> > the >> >> Same as the previous patch, this smells like intel-isms. Hardware that >> has native bcsel with support for two inline immediates will do better >> without. > > 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. You're right. I don't know what I was thinking. ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/6] nir: Turn bcsel of +/- 1.0 and 0.0 into b2f sequences.
On Aug 10, 2016 1:02 AM, "Erik Faye-Lund" wrote: > > On Wed, Aug 10, 2016 at 4:30 AM, Kenneth Graunke wrote: > > On Haswell (GL 3.3): > > > > total instructions in shared programs: 6208759 -> 6203860 (-0.08%) > > instructions in affected programs: 856541 -> 851642 (-0.57%) > > helped: 3157 > > HURT: 113 > > LOST: 7 > > GAINED: 15 > > > > On Broadwell (GL 4.4): > > > > total instructions in shared programs: 11637854 -> 11632016 (-0.05%) > > instructions in affected programs: 1055693 -> 1049855 (-0.55%) > > helped: 3900 > > HURT: 176 > > LOST: 1 > > GAINED: 18 > > > > Signed-off-by: Kenneth Graunke > > --- > > src/compiler/nir/nir_opt_algebraic.py | 4 > > 1 file changed, 4 insertions(+) > > > > diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py > > index 1cf614c..4e9896f 100644 > > --- a/src/compiler/nir/nir_opt_algebraic.py > > +++ b/src/compiler/nir/nir_opt_algebraic.py > > @@ -251,6 +251,10 @@ optimizations = [ > > (('ieq', 'a@bool', False), ('inot', 'a')), > > (('bcsel', a, True, False), ('ine', a, 0)), > > (('bcsel', a, False, True), ('ieq', a, 0)), > > + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))), > > + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))), > > + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0, > > + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0, > > (('bcsel', True, b, c), b), > > (('bcsel', False, b, c), c), > > # The result of this should be hit by constant propagation and, in the > > Same as the previous patch, this smells like intel-isms. Hardware that > has native bcsel with support for two inline immediates will do better > without. 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. ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/6] nir: Turn bcsel of +/- 1.0 and 0.0 into b2f sequences.
On Wed, Aug 10, 2016 at 4:30 AM, Kenneth Graunke wrote: > On Haswell (GL 3.3): > > total instructions in shared programs: 6208759 -> 6203860 (-0.08%) > instructions in affected programs: 856541 -> 851642 (-0.57%) > helped: 3157 > HURT: 113 > LOST: 7 > GAINED: 15 > > On Broadwell (GL 4.4): > > total instructions in shared programs: 11637854 -> 11632016 (-0.05%) > instructions in affected programs: 1055693 -> 1049855 (-0.55%) > helped: 3900 > HURT: 176 > LOST: 1 > GAINED: 18 > > Signed-off-by: Kenneth Graunke > --- > src/compiler/nir/nir_opt_algebraic.py | 4 > 1 file changed, 4 insertions(+) > > diff --git a/src/compiler/nir/nir_opt_algebraic.py > b/src/compiler/nir/nir_opt_algebraic.py > index 1cf614c..4e9896f 100644 > --- a/src/compiler/nir/nir_opt_algebraic.py > +++ b/src/compiler/nir/nir_opt_algebraic.py > @@ -251,6 +251,10 @@ optimizations = [ > (('ieq', 'a@bool', False), ('inot', 'a')), > (('bcsel', a, True, False), ('ine', a, 0)), > (('bcsel', a, False, True), ('ieq', a, 0)), > + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))), > + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))), > + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0, > + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0, > (('bcsel', True, b, c), b), > (('bcsel', False, b, c), c), > # The result of this should be hit by constant propagation and, in the Same as the previous patch, this smells like intel-isms. Hardware that has native bcsel with support for two inline immediates will do better without. ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 2/6] nir: Turn bcsel of +/- 1.0 and 0.0 into b2f sequences.
On Haswell (GL 3.3): total instructions in shared programs: 6208759 -> 6203860 (-0.08%) instructions in affected programs: 856541 -> 851642 (-0.57%) helped: 3157 HURT: 113 LOST: 7 GAINED: 15 On Broadwell (GL 4.4): total instructions in shared programs: 11637854 -> 11632016 (-0.05%) instructions in affected programs: 1055693 -> 1049855 (-0.55%) helped: 3900 HURT: 176 LOST: 1 GAINED: 18 Signed-off-by: Kenneth Graunke --- src/compiler/nir/nir_opt_algebraic.py | 4 1 file changed, 4 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 1cf614c..4e9896f 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -251,6 +251,10 @@ optimizations = [ (('ieq', 'a@bool', False), ('inot', 'a')), (('bcsel', a, True, False), ('ine', a, 0)), (('bcsel', a, False, True), ('ieq', a, 0)), + (('bcsel@32', a, 1.0, 0.0), ('b2f', ('ine', a, 0))), + (('bcsel@32', a, 0.0, 1.0), ('b2f', ('ieq', a, 0))), + (('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', ('ine', a, 0, + (('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('ieq', a, 0, (('bcsel', True, b, c), b), (('bcsel', False, b, c), c), # The result of this should be hit by constant propagation and, in the -- 2.9.0 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev