[Mesa-dev] [PATCH v2 7/7] nir/opt_algebraic: Add some constant bcsel reductions

Kenneth Graunke kenneth at whitecape.org
Thu Jan 29 17:02:28 PST 2015


On Thursday, January 29, 2015 02:34:18 PM Jason Ekstrand wrote:
> total instructions in shared programs: 5998190 -> 5997603 (-0.01%)
> instructions in affected programs:     54276 -> 53689 (-1.08%)
> helped:                                293
> ---
>  src/glsl/nir/nir_opt_algebraic.py | 30 ++++++++++++++++++++++++++++--
>  1 file changed, 28 insertions(+), 2 deletions(-)
> 
> diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py
> index e3b309c..3223119 100644
> --- a/src/glsl/nir/nir_opt_algebraic.py
> +++ b/src/glsl/nir/nir_opt_algebraic.py
> @@ -120,11 +120,37 @@ optimizations = [
>     # Boolean simplifications
>     (('ine', 'a at bool', 0), 'a'),
>     (('ieq', 'a at bool', 0), ('inot', 'a')),
> -   (('bcsel', 'a at bool', True, False), 'a'),
> -   (('bcsel', 'a at bool', False, True), ('inot', 'a')),
> +   (('bcsel', a, True, False), ('ine', a, 0)),
> +   (('bcsel', a, False, True), ('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
> +   # next round of opt_algebraic, get picked up by one of the above two.
> +   (('bcsel', '#a', b, c), ('bcsel', ('ine', 'a', 0), b, c)),
>  
>  # This one may not be exact
>     (('feq', ('fadd', a, b), 0.0), ('feq', a, ('fneg', b))),
>  ]
>  
> +# Add optimizations to handle the case where the result of a ternary is
> +# compared to a constant.  This way we can take things like
> +#
> +# (a ? 0 : 1) > 0
> +#
> +# and turn it into
> +#
> +# a ? (0 > 0) : (1 > 0)
> +#
> +# which constant folding will eat for lunch.  The resulting ternary will
> +# further get cleaned up by the boolean reductions above ane we will be

                                                 typo (and) ^^^

Series is:
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

> +# left with just the original variable "a".
> +for op in ['flt', 'fge', 'feq', 'fne',
> +           'ilt', 'ige', 'ieq', 'ine', 'ult', 'uge']:
> +   optimizations += [
> +      ((op, ('bcsel', 'a', '#b', '#c'), '#d'),
> +       ('bcsel', 'a', (op, 'b', 'd'), (op, 'c', 'd'))),
> +      ((op, '#d', ('bcsel', a, '#b', '#c')),
> +       ('bcsel', 'a', (op, 'd', 'b'), (op, 'd', 'c'))),
> +   ]
> +
>  print nir_algebraic.AlgebraicPass("nir_opt_algebraic", optimizations).render()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150129/17e5dd60/attachment-0001.sig>


More information about the mesa-dev mailing list