[Mesa-dev] [PATCH 2/2] nir: Reuse nir_src_as_const_val() in one more place.
Eric Anholt
eric at anholt.net
Wed Mar 16 03:41:26 UTC 2016
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]];
}
/* We shouldn't have any source modifiers in the optimization loop. */
--
2.7.0
More information about the mesa-dev
mailing list