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

Eric Anholt eric at anholt.net
Wed Mar 16 03:41:25 UTC 2016


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;
+      }
+   }
+
    return progress;
 }
 
-- 
2.7.0



More information about the mesa-dev mailing list