<p dir="ltr">This looks totally sane to me.</p>
<p dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>></p>
<p dir="ltr">I'll try and get some shader-db numbers for you tomorrow.<br>
--Jason<br></p>
<p dir="ltr">On May 21, 2015 5:07 PM, "Connor Abbott" <<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>> wrote:<br>
><br>
> Some loops may have phi nodes that look like:<br>
><br>
> foo = ...<br>
> loop {<br>
> bar = phi(foo, bar)<br>
> ...<br>
> }<br>
><br>
> in which case we can remove the phi node and replace all uses of 'bar'<br>
> with 'foo'. In particular, there are some L4D2 vertex shaders with loops<br>
> that, after optimization, look like:<br>
><br>
> /* succs: block_1 */<br>
> loop {<br>
> block block_1:<br>
> /* preds: block_0 block_4 */<br>
> vec1 ssa_2195 = phi block_0: ssa_2136, block_4: ssa_994<br>
> vec1 ssa_7321 = phi block_0: ssa_8195, block_4: ssa_7321<br>
> vec1 ssa_7324 = phi block_0: ssa_8198, block_4: ssa_7324<br>
> vec1 ssa_7327 = phi block_0: ssa_8174, block_4: ssa_7327<br>
> vec1 ssa_8139 = intrinsic load_uniform () () (232)<br>
> vec1 ssa_588 = ige ssa_2195, ssa_8139<br>
> /* succs: block_2 block_3 */<br>
> if ssa_588 {<br>
> block block_2:<br>
> /* preds: block_1 */<br>
> break<br>
> /* succs: block_5 */<br>
> } else {<br>
> block block_3:<br>
> /* preds: block_1 */<br>
> /* succs: block_4 */<br>
> }<br>
> block block_4:<br>
> /* preds: block_3 */<br>
> vec1 ssa_994 = iadd ssa_2195, ssa_2150<br>
> /* succs: block_1 */<br>
> }<br>
><br>
> where after removing the second, third, and fourth phi nodes, the loop<br>
> becomes entirely dead, and this patch combined with my nir-dead-cf-v4<br>
> branch will cause the loop to be deleted entirely.<br>
><br>
> No piglit regressions.<br>
><br>
> Signed-off-by: Connor Abbott <<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>><br>
> ---<br>
> src/glsl/nir/nir_opt_remove_phis.c | 20 ++++++++++++++++++++<br>
> 1 file changed, 20 insertions(+)<br>
><br>
> diff --git a/src/glsl/nir/nir_opt_remove_phis.c b/src/glsl/nir/nir_opt_remove_phis.c<br>
> index 7896584..3660413 100644<br>
> --- a/src/glsl/nir/nir_opt_remove_phis.c<br>
> +++ b/src/glsl/nir/nir_opt_remove_phis.c<br>
> @@ -60,6 +60,21 @@ remove_phis_block(nir_block *block, void *state)<br>
><br>
> nir_foreach_phi_src(phi, src) {<br>
> assert(src->src.is_ssa);<br>
> +<br>
> + /* For phi nodes at the beginning of loops, we may encounter some<br>
> + * sources from backedges that point back to the destination of the<br>
> + * same phi, i.e. something like:<br>
> + *<br>
> + * a = phi(a, b, ...)<br>
> + *<br>
> + * We can safely ignore these sources, since if all of the normal<br>
> + * sources point to the same definition, then that definition must<br>
> + * still dominate the phi node, and the phi will still always take<br>
> + * the value of that definition.<br>
> + */<br>
> +<br>
> + if (src->src.ssa == &phi->dest.ssa)<br>
> + continue;<br>
><br>
> if (def == NULL) {<br>
> def = src->src.ssa;<br>
> @@ -74,6 +89,11 @@ remove_phis_block(nir_block *block, void *state)<br>
> if (!srcs_same)<br>
> continue;<br>
><br>
> + /* We must have found at least one definition, since there must be at<br>
> + * least one forward edge.<br>
> + */<br>
> + assert(def != NULL);<br>
> +<br>
> assert(phi->dest.is_ssa);<br>
> nir_ssa_def_rewrite_uses(&phi->dest.ssa, nir_src_for_ssa(def),<br>
> mem_ctx);<br>
> --<br>
> 2.1.0<br>
><br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</p>