[Mesa-dev] [PATCH 5/9] nir: Add a flag for lowering fneg/ineg.

Connor Abbott cwabbott0 at gmail.com
Sun Feb 1 13:43:59 PST 2015


I think this logic should be flipped around... you should have a flag
'lower_sub' which is false for vc4 but true for i965, and then if the
flag is true we lower sub to add+neg and if false we try and
reconstruct sub (and do other things like pulling neg's out of
multiplies). That way, eventually we can turn off the lowering in GLSL
IR and in the future pass a subtract in the GLSL source all the way
down to the driver without lowering it and then un-lowering it.

On Sun, Feb 1, 2015 at 4:17 PM, Eric Anholt <eric at anholt.net> wrote:
> vc4 cse/algebraic-disabled stats:
> total instructions in shared programs: 44911 -> 44732 (-0.40%)
> instructions in affected programs:     11371 -> 11192 (-1.57%)
> ---
>  src/gallium/drivers/vc4/vc4_program.c |  1 +
>  src/glsl/nir/nir.h                    |  2 ++
>  src/glsl/nir/nir_opt_algebraic.py     | 10 ++++++++++
>  3 files changed, 13 insertions(+)
>
> diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c
> index fd818b4..304cd04 100644
> --- a/src/gallium/drivers/vc4/vc4_program.c
> +++ b/src/gallium/drivers/vc4/vc4_program.c
> @@ -2100,6 +2100,7 @@ nir_to_qir(struct vc4_compile *c)
>  static const nir_shader_compiler_options nir_options = {
>          .lower_fpow = true,
>          .lower_fsqrt = true,
> +        .lower_negate = true,
>  };
>
>  static struct vc4_compile *
> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
> index b0ad4b0..0746adf 100644
> --- a/src/glsl/nir/nir.h
> +++ b/src/glsl/nir/nir.h
> @@ -1329,6 +1329,8 @@ typedef struct nir_function {
>  typedef struct nir_shader_compiler_options {
>     bool lower_fpow;
>     bool lower_fsqrt;
> +   /** lowers fneg and ineg to fsub and isub. */
> +   bool lower_negate;
>  } nir_shader_compiler_options;
>
>  typedef struct nir_shader {
> diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py
> index 2020997..7d5f543 100644
> --- a/src/glsl/nir/nir_opt_algebraic.py
> +++ b/src/glsl/nir/nir_opt_algebraic.py
> @@ -136,6 +136,16 @@ optimizations = [
>     (('bcsel', a, b, b), b),
>     (('fcsel', a, b, b), b),
>
> +   # Subtracts
> +   (('fsub', 0.0, ('fsub', 0.0, a)), a),
> +   (('isub', 0, ('isub', 0, a)), a),
> +   (('fneg', a), ('fsub', 0.0, a), 'options->lower_negate'),
> +   (('ineg', a), ('isub', 0, a), 'options->lower_negate'),
> +   (('fadd', a, ('fsub', 0.0, b)), ('fsub', a, b)),
> +   (('iadd', a, ('isub', 0, b)), ('isub', a, b)),
> +   (('fabs', ('fsub', 0.0, a)), ('fabs', a)),
> +   (('iabs', ('isub', 0, a)), ('fabs', a)),
> +
>  # This one may not be exact
>     (('feq', ('fadd', a, b), 0.0), ('feq', a, ('fneg', b))),
>  ]
> --
> 2.1.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list