[Mesa-dev] [PATCH] nir: Transform discard_if(true) into discard

Jason Ekstrand jason at jlekstrand.net
Fri Apr 27 20:44:11 UTC 2018


On Fri, Apr 27, 2018 at 12:17 PM, Matt Turner <mattst88 at gmail.com> wrote:

> Noticed while reviewing Tim Arceri's NIR inlining series.
>
> Without his series:
>
> instructions in affected programs: 16 -> 14 (-12.50%)
> helped: 2
>
> With his series:
>
> instructions in affected programs: 196 -> 174 (-11.22%)
> helped: 22
> ---
>  src/compiler/nir/nir_opt_constant_folding.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/src/compiler/nir/nir_opt_constant_folding.c
> b/src/compiler/nir/nir_opt_constant_folding.c
> index a848b145874..fe34f4ade8b 100644
> --- a/src/compiler/nir/nir_opt_constant_folding.c
> +++ b/src/compiler/nir/nir_opt_constant_folding.c
> @@ -167,7 +167,22 @@ constant_fold_intrinsic_instr(nir_intrinsic_instr
> *instr)
>
>     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->u32[0] == 0) {
> +      if (src_val && src_val->u32[0] == NIR_FALSE) {
> +         nir_instr_remove(&instr->instr);
> +         progress = true;
> +      } else if (src_val && src_val->u32[0] == NIR_TRUE) {
> +         /* This method of getting a nir_shader * from a nir_instr is
> +          * admittedly gross, but given the rarity of hitting this case I
> think
> +          * it's preferable to plumbing an otherwise unused nir_shader *
> +          * parameter through four functions to get here.
> +          */
> +         nir_cf_node *cf_node = &instr->instr.block->cf_node;
> +         nir_function_impl *impl = nir_cf_node_get_function(cf_node);
> +         nir_shader *shader = impl->function->shader;
> +
>

Yeah, this works fine.

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


> +         nir_intrinsic_instr *discard =
> +            nir_intrinsic_instr_create(shader, nir_intrinsic_discard);
> +         nir_instr_insert_before(&instr->instr, &discard->instr);
>           nir_instr_remove(&instr->instr);
>           progress = true;
>        }
> --
> 2.16.1
>
> _______________________________________________
> 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/20180427/8f7f10f7/attachment.html>


More information about the mesa-dev mailing list