<p dir="ltr"></p>
<p dir="ltr">On Aug 11, 2016 6:16 PM, "Ian Romanick" <<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>> wrote:<br>
><br>
> On 08/11/2016 11:54 AM, Thomas Helland wrote:<br>
> > 2016-08-11 18:19 GMT+02:00 Ian Romanick <<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>>:<br>
> >> ping<br>
> >><br>
> >> On 07/19/2016 10:37 PM, Ian Romanick wrote:<br>
> >>> From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
> >>><br>
> >>> Some shaders include code that looks like:<br>
> >>><br>
> >>> uniform int i;<br>
> >>> uniform vec4 bones[...];<br>
> >>><br>
> >>> foo(bones[i * 3], bones[i * 3 + 1], bones[i * 3 + 2]);<br>
> >>><br>
> >>> CSE would do some work on this:<br>
> >>><br>
> >>> x = i * 3<br>
> >>> foo(bones[x], bones[x + 1], bones[x + 2]);<br>
> >>><br>
> >>> The compiler may then add '<< 4 + base' to the index calculations.<br>
> >>> This results in expressions like<br>
> >>><br>
> >>> x = i * 3<br>
> >>> foo(bones[x << 4], bones[(x + 1) << 4], bones[(x + 2) << 4]);<br>
> >>><br>
> ><br>
> > This may just be me being dense, but why is the compiler adding the shift?<br>
> > It seems like this would be "un-optimizing" and so it shouldn't be added?<br>
><br>
> The shift is to convert the array offset to a byte offset. A vec4 is 16<br>
> bytes.<br>
><br>
> > This patch is also a good argument for adding a constant reassociation pass.<br>
> > At least the (a * #b) << #c ---> a * (#b << #c) would be caught by that.<br>
> ><br>
> > I was confused whether the optimization was preserving signed-ness correctly<br>
> > but after a couple rounds with myself I believe it is correct.</p>
<p dir="ltr">I believe so too. "<< c" as an operator is equivalent to "* (1 << c)" so association and distributivity apply.</p>
<p dir="ltr">> > The change looks good and is:<br>
> ><br>
> > Reviewed-by: Thomas Helland <<a href="mailto:thomashelland90@gmail.com">thomashelland90@gmail.com</a>></p>
<p dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>></p>
<p dir="ltr">> > (Oh, and yes, I'm back to hobby mesa development after finally<br>
> > securing a new job and a new apartment)<br>
><br>
> Welcome back!</p>
<p dir="ltr">Woohoo!</p>
<p dir="ltr">> >>> Just rearranging the math to produce (i * 48) + 16 saves an<br>
> >>> instruction, and it allows CSE to do more work.<br>
> >>><br>
> >>> x = i * 48;<br>
> >>> foo(bones[x], bones[x + 16], bones[x + 32]);<br>
> >>><br>
> >>> So, ~6 instructions becomes ~3.<br>
> >>><br>
> >>> Some individual shader-db results look pretty bad. However, I have a<br>
> >>> really, really hard time believing the change in estimated cycles in,<br>
> >>> for example, 3dmmes-taiji/51.shader_test after looking that change in<br>
> >>> the generated code.<br>
> >>><br>
> >>> G45<br>
> >>> total instructions in shared programs: 4020840 -> 4010070 (-0.27%)<br>
> >>> instructions in affected programs: 177460 -> 166690 (-6.07%)<br>
> >>> helped: 894<br>
> >>> HURT: 0<br>
> >>><br>
> >>> total cycles in shared programs: 98829000 -> 98784990 (-0.04%)<br>
> >>> cycles in affected programs: 3936648 -> 3892638 (-1.12%)<br>
> >>> helped: 894<br>
> >>> HURT: 0<br>
> >>><br>
> >>> Ironlake<br>
> >>> total instructions in shared programs: 6418887 -> 6408117 (-0.17%)<br>
> >>> instructions in affected programs: 177460 -> 166690 (-6.07%)<br>
> >>> helped: 894<br>
> >>> HURT: 0<br>
> >>><br>
> >>> total cycles in shared programs: 143504542 -> 143460532 (-0.03%)<br>
> >>> cycles in affected programs: 3936648 -> 3892638 (-1.12%)<br>
> >>> helped: 894<br>
> >>> HURT: 0<br>
> >>><br>
> >>> Sandy Bridge<br>
> >>> total instructions in shared programs: 8357887 -> 8339251 (-0.22%)<br>
> >>> instructions in affected programs: 432715 -> 414079 (-4.31%)<br>
> >>> helped: 2795<br>
> >>> HURT: 0<br>
> >>><br>
> >>> total cycles in shared programs: 118284184 -> 118207412 (-0.06%)<br>
> >>> cycles in affected programs: 6114626 -> 6037854 (-1.26%)<br>
> >>> helped: 2478<br>
> >>> HURT: 317<br>
> >>><br>
> >>> Ivy Bridge<br>
> >>> total instructions in shared programs: 7669390 -> 7653822 (-0.20%)<br>
> >>> instructions in affected programs: 388234 -> 372666 (-4.01%)<br>
> >>> helped: 2795<br>
> >>> HURT: 0<br>
> >>><br>
> >>> total cycles in shared programs: 68381982 -> 68263684 (-0.17%)<br>
> >>> cycles in affected programs: 1972658 -> 1854360 (-6.00%)<br>
> >>> helped: 2458<br>
> >>> HURT: 307<br>
> >>><br>
> >>> Haswell<br>
> >>> total instructions in shared programs: 7082636 -> 7067068 (-0.22%)<br>
> >>> instructions in affected programs: 388234 -> 372666 (-4.01%)<br>
> >>> helped: 2795<br>
> >>> HURT: 0<br>
> >>><br>
> >>> total cycles in shared programs: 68282020 -> 68164158 (-0.17%)<br>
> >>> cycles in affected programs: 1891820 -> 1773958 (-6.23%)<br>
> >>> helped: 2459<br>
> >>> HURT: 261<br>
> >>><br>
> >>> Broadwell<br>
> >>> total instructions in shared programs: 9002466 -> 8985875 (-0.18%)<br>
> >>> instructions in affected programs: 658784 -> 642193 (-2.52%)<br>
> >>> helped: 2795<br>
> >>> HURT: 5<br>
> >>><br>
> >>> total cycles in shared programs: 78503092 -> 78450404 (-0.07%)<br>
> >>> cycles in affected programs: 2873304 -> 2820616 (-1.83%)<br>
> >>> helped: 2275<br>
> >>> HURT: 415<br>
> >>><br>
> >>> Skylake<br>
> >>> total instructions in shared programs: 9156978 -> 9140387 (-0.18%)<br>
> >>> instructions in affected programs: 682625 -> 666034 (-2.43%)<br>
> >>> helped: 2795<br>
> >>> HURT: 5<br>
> >>><br>
> >>> total cycles in shared programs: 75591392 -> 75550574 (-0.05%)<br>
> >>> cycles in affected programs: 3192120 -> 3151302 (-1.28%)<br>
> >>> helped: 2271<br>
> >>> HURT: 425<br>
> >>><br>
> >>> Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
> >>> ---<br>
> >>> src/compiler/nir/nir_opt_algebraic.py | 11 +++++++++++<br>
> >>> 1 file changed, 11 insertions(+)<br>
> >>><br>
> >>> diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py<br>
> >>> index 0f0896b..37cb700 100644<br>
> >>> --- a/src/compiler/nir/nir_opt_algebraic.py<br>
> >>> +++ b/src/compiler/nir/nir_opt_algebraic.py<br>
> >>> @@ -119,6 +119,17 @@ optimizations = [<br>
> >>> (('~fadd@64', a, ('fmul', c , ('fadd', b, ('fneg', a)))), ('flrp', a, b, c), '!options->lower_flrp64'),<br>
> >>> (('ffma', a, b, c), ('fadd', ('fmul', a, b), c), 'options->lower_ffma'),<br>
> >>> (('~fadd', ('fmul', a, b), c), ('ffma', a, b, c), 'options->fuse_ffma'),<br>
> >>> +<br>
> >>> + # (a * #b + #c) << #d<br>
> >>> + # ((a * #b) << #d) + (#c << #d)<br>
> >>> + # (a * (#b << #d)) + (#c << #d)<br>
> >>> + (('ishl', ('iadd', ('imul', a, '#b'), '#c'), '#d'),<br>
> >>> + ('iadd', ('imul', a, ('ishl', b, d)), ('ishl', c, d))),<br>
> >>> +<br>
> >>> + # (a * #b) << #c<br>
> >>> + # a * (#b << #c)<br>
> >>> + (('ishl', ('imul', a, '#b'), '#c'), ('imul', a, ('ishl', b, c))),<br>
> >>> +<br>
> >>> # Comparison simplifications<br>
> >>> (('~inot', ('flt', a, b)), ('fge', a, b)),<br>
> >>> (('~inot', ('fge', a, b)), ('flt', a, b)),<br>
> >>><br>
> >><br>
> >> _______________________________________________<br>
> >> mesa-dev mailing list<br>
> >> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> >> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
> ><br>
><br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br></p>