[Mesa-dev] [PATCH 1/2] nir: Optimize out discard_ifs with a constant 0 argument.

Jason Ekstrand jason at jlekstrand.net
Wed Mar 16 03:57:55 UTC 2016


On Tue, Mar 15, 2016 at 8:41 PM, Eric Anholt <eric at anholt.net> wrote:

> I found this in a shader that was doing an alpha test when alpha is fixed
> at 1.0.
>
> instructions in affected programs:     16 -> 15 (-6.25%)
> total uniforms in shared programs: 28703 -> 28703 (0.00%)
> ---
>  src/compiler/nir/nir_opt_constant_folding.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/src/compiler/nir/nir_opt_constant_folding.c
> b/src/compiler/nir/nir_opt_constant_folding.c
> index 04876a4..8a353c2 100644
> --- a/src/compiler/nir/nir_opt_constant_folding.c
> +++ b/src/compiler/nir/nir_opt_constant_folding.c
> @@ -130,6 +130,14 @@ constant_fold_intrinsic_instr(nir_intrinsic_instr
> *instr)
>        progress |= constant_fold_deref(&instr->instr, instr->variables[i]);
>     }
>
> +   if (instr->intrinsic == nir_intrinsic_discard_if) {
> +      nir_const_value *src_val = nir_src_as_const_value(instr->src[0]);
> +      if (src_val && src_val->u[0] == 0) {
> +         nir_instr_remove(&instr->instr);
> +         progress = true;
> +      }
> +   }
>

opt_constant_folding seems like a strange place to put this, but I can't
think of anything better.

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>


> +
>     return progress;
>  }
>
> --
> 2.7.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160315/9f260882/attachment-0001.html>


More information about the mesa-dev mailing list