[Mesa-dev] [PATCH 1/2] nir: optimize min(min(a, b), c) to min3(a, b, c) under an option

Ian Romanick idr at freedesktop.org
Fri Jun 1 00:17:07 UTC 2018


On 05/30/2018 10:06 AM, Samuel Pitoiset wrote:
> Similar for max().
> 
> Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
> ---
>  src/compiler/nir/nir.h                | 3 +++
>  src/compiler/nir/nir_opt_algebraic.py | 8 ++++++++
>  2 files changed, 11 insertions(+)
> 
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index f6086bd6c0..04991b7d04 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -1897,6 +1897,9 @@ typedef struct nir_shader_compiler_options {
>     /* lower b2f to iand */
>     bool lower_b2f;
>  
> +   /* lower min(min(a, b), c) to min3(a, b, c) (same for max()). */
> +   bool lower_minmax3;

The way this variable is named and the way it is used is confusing.
Every other lower_foo means "convert foo to something else."  This one
means "make some foo."

> +
>     /* Does the native fdot instruction replicate its result for four
>      * components?  If so, then opt_algebraic_late will turn all fdotN
>      * instructions into fdot_replicatedN instructions.
> diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
> index 909ea3daf4..1d67e2d88c 100644
> --- a/src/compiler/nir/nir_opt_algebraic.py
> +++ b/src/compiler/nir/nir_opt_algebraic.py
> @@ -224,6 +224,14 @@ optimizations = [
>     (('imax', a, a), a),
>     (('umin', a, a), a),
>     (('umax', a, a), a),
> +
> +   (('fmin', ('fmin', a, b), c), ('fmin3', a, b, c), 'options->lower_minmax3'),
> +   (('imin', ('imin', a, b), c), ('imin3', a, b, c), 'options->lower_minmax3'),
> +   (('umin', ('umin', a, b), c), ('umin3', a, b, c), 'options->lower_minmax3'),
> +   (('fmax', ('fmax', a, b), c), ('fmax3', a, b, c), 'options->lower_minmax3'),
> +   (('imax', ('imax', a, b), c), ('imax3', a, b, c), 'options->lower_minmax3'),
> +   (('umax', ('umax', a, b), c), ('umax3', a, b, c), 'options->lower_minmax3'),
> +
>     (('fmin', a, ('fneg', a)), ('fneg', ('fabs', a))),
>     (('imin', a, ('ineg', a)), ('ineg', ('iabs', a))),
>     (('fmin', a, ('fneg', ('fabs', a))), ('fneg', ('fabs', a))),
> 



More information about the mesa-dev mailing list