[Mesa-dev] [PATCH 2/2] nir: Reuse nir_src_as_const_val() in one more place.

Jason Ekstrand jason at jlekstrand.net
Wed Mar 16 03:58:47 UTC 2016


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

> I copy and pasted this code before finding the helper.
> ---
>  src/compiler/nir/nir_opt_constant_folding.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/src/compiler/nir/nir_opt_constant_folding.c
> b/src/compiler/nir/nir_opt_constant_folding.c
> index 8a353c2..190a509 100644
> --- a/src/compiler/nir/nir_opt_constant_folding.c
> +++ b/src/compiler/nir/nir_opt_constant_folding.c
> @@ -47,18 +47,14 @@ constant_fold_alu_instr(nir_alu_instr *instr, void
> *mem_ctx)
>        return false;
>
>     for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; i++) {
> -      if (!instr->src[i].src.is_ssa)
> -         return false;
> -
> -      nir_instr *src_instr = instr->src[i].src.ssa->parent_instr;
> +      nir_const_value *src_val =
> nir_src_as_const_value(instr->src[i].src);
>
> -      if (src_instr->type != nir_instr_type_load_const)
> +      if (!src_val)
>           return false;
> -      nir_load_const_instr* load_const =
> nir_instr_as_load_const(src_instr);
>
>        for (unsigned j = 0; j < nir_ssa_alu_instr_src_components(instr, i);
>             j++) {
> -         src[i].u[j] = load_const->value.u[instr->src[i].swizzle[j]];
> +         src[i].u[j] = src_val->u[instr->src[i].swizzle[j]];
>

Much better.

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


>        }
>
>        /* We shouldn't have any source modifiers in the optimization loop.
> */
> --
> 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/53042364/attachment.html>


More information about the mesa-dev mailing list