[Mesa-dev] [PATCH 06/10] nir: Add a bunch of algebraic optimizations on logic/bit operations.

Jason Ekstrand jason at jlekstrand.net
Thu Jan 22 07:27:05 PST 2015


On Jan 22, 2015 3:41 AM, "Kenneth Graunke" <kenneth at whitecape.org> wrote:
>
> Matt and I noticed a bunch of "val <- ior a a" operations in a shader,
> so we decided to add an algebraic optimization for that.  While there,
> I decided to add a bunch more of them.
>
> total NIR instructions in shared programs: 2023511 -> 2020814 (-0.13%)
> NIR instructions in affected programs:     149634 -> 146937 (-1.80%)
> helped:                                    1032
>
> i965 already cleans these up, so the final results aren't impressive:
>
> total i965 instructions in shared programs: 6035392 -> 6035397 (0.00%)
> i965 instructions in affected programs:     764 -> 769 (0.65%)
> HURT:                                       3
>
> However, improving the result of the NIR compile is worth doing.
>
> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> ---
>  src/glsl/nir/nir_opt_algebraic.py | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/src/glsl/nir/nir_opt_algebraic.py
b/src/glsl/nir/nir_opt_algebraic.py
> index 169bb41..cf16b19 100644
> --- a/src/glsl/nir/nir_opt_algebraic.py
> +++ b/src/glsl/nir/nir_opt_algebraic.py
> @@ -68,6 +68,22 @@ optimizations = [
>     (('fadd', ('fmul', a, b), c), ('ffma', a, b, c)),
>     (('fge', ('fneg', ('fabs', a)), 0.0), ('feq', a, 0.0)),
>     (('fmin', ('fmax', a, 1.0), 0.0), ('fsat', a)),
> +   # Logical and bit operations
> +   (('fand', a, a), a),

This isn't correct.  The fand operation will normalize to 0.0/1.0.

> +   (('fand', a, 0.0), 0.0),

This is ok

> +   (('iand', a, a), a),
> +   (('iand', a, 0), 0),
> +   (('for', a, a), a),
> +   (('for', a, 0.0), a),

Can't do these two either

> +   (('ior', a, a), a),
> +   (('ior', a, 0), a),
> +   (('fxor', a, a), 0.0),

This one should be ok

With the junk optimizations removed,
Reviewed-by: Jason Ekstrand <jason.ekstrand at intel.com>

> +   (('ixor', a, a), 0),
> +   (('inot', ('inot', a)), a),
> +   # DeMorgan's Laws
> +   (('iand', ('inot', a), ('inot', b)), ('inot', ('ior',  a, b))),
> +   (('ior',  ('inot', a), ('inot', b)), ('inot', ('iand', a, b))),
> +
>  # This one may not be exact
>     (('feq', ('fadd', a, b), 0.0), ('feq', a, ('fneg', b))),
>  ]
> --
> 2.2.2
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150122/3edb43a0/attachment-0001.html>


More information about the mesa-dev mailing list