[Mesa-dev] [PATCH] nir: Optimize useless comparisons against true/false.

Jason Ekstrand jason at jlekstrand.net
Wed Dec 2 13:34:42 PST 2015


On Tue, Dec 1, 2015 at 4:16 PM, Matt Turner <mattst88 at gmail.com> wrote:
> ---
> I add the true/false variables for clarity since there are some existing
> optimizations using ~0 where it actually has nothing to do with true.
>
> I could take it or leave it. We obviously can't use them for feq and
> friends. Maybe itrue/ifalse and ftrue/ffalse?
>
>  src/glsl/nir/nir_opt_algebraic.py | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py
> index 6aa8b1f..04261e7 100644
> --- a/src/glsl/nir/nir_opt_algebraic.py
> +++ b/src/glsl/nir/nir_opt_algebraic.py
> @@ -32,6 +32,9 @@ b = 'b'
>  c = 'c'
>  d = 'd'
>
> +true = ~0
> +false = 0

I think you can just use the python True and False and it works fine.
With that changed,

Reviewed-by: Jason Ekstrand <jason.ekstrand at intel.com>

> +
>  # Written in the form (<search>, <replace>) where <search> is an expression
>  # and <replace> is either an expression or a value.  An expression is
>  # defined as a tuple of the form (<op>, <src0>, <src1>, <src2>, <src3>)
> @@ -94,6 +97,8 @@ optimizations = [
>     (('inot', ('ige', a, b)), ('ilt', a, b)),
>     (('inot', ('ieq', a, b)), ('ine', a, b)),
>     (('inot', ('ine', a, b)), ('ieq', a, b)),
> +   (('ieq', 'a at bool', true), a),
> +   (('ine', 'a at bool', false), a),
>     (('fge', ('fneg', ('fabs', a)), 0.0), ('feq', a, 0.0)),
>     (('bcsel', ('flt', a, b), a, b), ('fmin', a, b)),
>     (('bcsel', ('flt', a, b), b, a), ('fmax', a, b)),
> --
> 2.4.9
>


More information about the mesa-dev mailing list