[Mesa-dev] [PATCH 3/3] nir: Add a bunch of b2[if] optimizations

Jason Ekstrand jason at jlekstrand.net
Thu Oct 11 16:36:43 UTC 2018


Ian,

This patch demonstrates the need for patch 2.  Without patch 2, it fails a
number of tests as one would expect.  I'm not really sure why you didn't
see fails without this but I didn't either.

--Jason

On Thu, Oct 11, 2018 at 10:38 AM Jason Ekstrand <jason at jlekstrand.net>
wrote:

> The b2f and b2i conversions always produce zero or one which are both
> representable in every type and size.  Since b2i and b2f support all bit
> sizes, we can just get rid of the conversion opcode.
>
> total instructions in shared programs: 15089335 -> 15084368 (-0.03%)
> instructions in affected programs: 212564 -> 207597 (-2.34%)
> helped: 896
> HURT: 0
>
> total cycles in shared programs: 369831123 -> 369826267 (<.01%)
> cycles in affected programs: 2008647 -> 2003791 (-0.24%)
> helped: 693
> HURT: 216
> ---
>  src/compiler/nir/nir_opt_algebraic.py | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>
> diff --git a/src/compiler/nir/nir_opt_algebraic.py
> b/src/compiler/nir/nir_opt_algebraic.py
> index 422a8794d38..cc747250ba5 100644
> --- a/src/compiler/nir/nir_opt_algebraic.py
> +++ b/src/compiler/nir/nir_opt_algebraic.py
> @@ -751,6 +751,23 @@ for left, right in
> itertools.combinations_with_replacement(invert.keys(), 2):
>     optimizations.append((('inot', ('iand(is_used_once)', (left, a, b),
> (right, c, d))),
>                           ('ior', (invert[left], a, b), (invert[right], c,
> d))))
>
> +# Optimize x2yN(b2x(x)) -> b2y
> +optimizations.append((('f2b', ('b2f', a)), a))
> +optimizations.append((('i2b', ('b2i', a)), a))
> +for x, y in itertools.product(['f', 'u', 'i'], ['f', 'u', 'i']):
> +   if x != 'f' and y != 'f' and x != y:
> +      continue
> +
> +   b2x = 'b2f' if x == 'f' else 'b2i'
> +   b2y = 'b2f' if y == 'f' else 'b2i'
> +
> +   for N in [8, 16, 32, 64]:
> +      if y == 'f' and N == 8:
> +         continue
> +
> +      x2yN = '{}2{}{}'.format(x, y, N)
> +      optimizations.append(((x2yN, (b2x, a)), (b2y, a)))
> +
>  def fexp2i(exp, bits):
>     # We assume that exp is already in the right range.
>     if bits == 32:
> --
> 2.19.1
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20181011/212347ea/attachment.html>


More information about the mesa-dev mailing list