summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_opt_constant_folding.c
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2016-03-15 18:32:19 -0700
committerEric Anholt <eric@anholt.net>2016-09-28 08:31:14 -0700
commit1aa8a0392f256a1be8f8d2774a4f7d3e03b3aac3 (patch)
tree37252635af501f6e59a0764117d4c73a30a34b30 /src/compiler/nir/nir_opt_constant_folding.c
parent8d8c440ebf1a41dd235a67f3f1538cf47adec013 (diff)
downloadexternal_mesa3d-1aa8a0392f256a1be8f8d2774a4f7d3e03b3aac3.zip
external_mesa3d-1aa8a0392f256a1be8f8d2774a4f7d3e03b3aac3.tar.gz
external_mesa3d-1aa8a0392f256a1be8f8d2774a4f7d3e03b3aac3.tar.bz2
nir: Optimize out discard_ifs with a constant 0 argument.
I found this in a shader that was doing an alpha test when alpha is fixed at 1.0. v2: Rebase on master (now the const value is "u32" not "u"). Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> (v1)
Diffstat (limited to 'src/compiler/nir/nir_opt_constant_folding.c')
-rw-r--r--src/compiler/nir/nir_opt_constant_folding.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_opt_constant_folding.c b/src/compiler/nir/nir_opt_constant_folding.c
index 8f04061..d6be807 100644
--- a/src/compiler/nir/nir_opt_constant_folding.c
+++ b/src/compiler/nir/nir_opt_constant_folding.c
@@ -155,6 +155,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->u32[0] == 0) {
+ nir_instr_remove(&instr->instr);
+ progress = true;
+ }
+ }
+
return progress;
}