<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Apr 27, 2018 at 12:17 PM, Matt Turner <span dir="ltr"><<a href="mailto:mattst88@gmail.com" target="_blank">mattst88@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Noticed while reviewing Tim Arceri's NIR inlining series.<br>
<br>
Without his series:<br>
<br>
instructions in affected programs: 16 -> 14 (-12.50%)<br>
helped: 2<br>
<br>
With his series:<br>
<br>
instructions in affected programs: 196 -> 174 (-11.22%)<br>
helped: 22<br>
---<br>
src/compiler/nir/nir_opt_<wbr>constant_folding.c | 17 ++++++++++++++++-<br>
1 file changed, 16 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/src/compiler/nir/nir_opt_<wbr>constant_folding.c b/src/compiler/nir/nir_opt_<wbr>constant_folding.c<br>
index a848b145874..fe34f4ade8b 100644<br>
--- a/src/compiler/nir/nir_opt_<wbr>constant_folding.c<br>
+++ b/src/compiler/nir/nir_opt_<wbr>constant_folding.c<br>
@@ -167,7 +167,22 @@ constant_fold_intrinsic_instr(<wbr>nir_intrinsic_instr *instr)<br>
<br>
if (instr->intrinsic == nir_intrinsic_discard_if) {<br>
nir_const_value *src_val = nir_src_as_const_value(instr-><wbr>src[0]);<br>
- if (src_val && src_val->u32[0] == 0) {<br>
+ if (src_val && src_val->u32[0] == NIR_FALSE) {<br>
+ nir_instr_remove(&instr-><wbr>instr);<br>
+ progress = true;<br>
+ } else if (src_val && src_val->u32[0] == NIR_TRUE) {<br>
+ /* This method of getting a nir_shader * from a nir_instr is<br>
+ * admittedly gross, but given the rarity of hitting this case I think<br>
+ * it's preferable to plumbing an otherwise unused nir_shader *<br>
+ * parameter through four functions to get here.<br>
+ */<br>
+ nir_cf_node *cf_node = &instr->instr.block->cf_node;<br>
+ nir_function_impl *impl = nir_cf_node_get_function(cf_<wbr>node);<br>
+ nir_shader *shader = impl->function->shader;<br>
+<br></blockquote><div><br></div><div>Yeah, this works fine.<br><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ nir_intrinsic_instr *discard =<br>
+ nir_intrinsic_instr_create(<wbr>shader, nir_intrinsic_discard);<br>
+ nir_instr_insert_before(&<wbr>instr->instr, &discard->instr);<br>
nir_instr_remove(&instr-><wbr>instr);<br>
progress = true;<br>
}<br>
<span class="HOEnZb"><font color="#888888">-- <br>
2.16.1<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>