From 25dcb8d201a226bdf4794281005c99fd8024cde0 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 1 Jun 2022 11:02:42 -0500 Subject: [PATCH] nir/from_ssa: Ignore undef sources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Is a phi source is an undef, there's no point in copying it or really caring about it at all. We would just end up inserting a mov from an undef to a register. Instead, treat phi sources which point to an undef as if the phi source doesn't exist. This also prevents them from being included in phi webs which should reduce the overall interference seen in the shader. Currently, if two phis share an undef, their phi webs are consdiered to interfere. By ignoring undefs we can get rid of this false interference and reduce the size of phi webs. Reducing the number of things being copied by the parallel copy instructions should also free up the paralle copy algorithm and reduce the over-all churn of movs. Shader-db results on Haswell: total instructions in shared programs: 8156608 -> 8155406 (-0.01%) instructions in affected programs: 164838 -> 163636 (-0.73%) Shader-db results on Skylake: total instructions in shared programs: 18227370 -> 18227359 (<.01%) instructions in affected programs: 519 -> 508 (-2.12%) helped: 6 HURT: 0 Shader-db results on Tigerlake: total instructions in shared programs: 21167987 -> 21168025 (<.01%) instructions in affected programs: 23701 -> 23739 (0.16%) helped: 21 HURT: 27 Reviewed-by: Daniel Schürmann Part-of: --- src/compiler/nir/nir_from_ssa.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/nir/nir_from_ssa.c b/src/compiler/nir/nir_from_ssa.c index 3bcac93302c..7456eab7686 100644 --- a/src/compiler/nir/nir_from_ssa.c +++ b/src/compiler/nir/nir_from_ssa.c @@ -408,6 +408,9 @@ isolate_phi_nodes_block(nir_shader *shader, nir_block *block, void *dead_ctx) nir_phi_instr *phi = nir_instr_as_phi(instr); assert(phi->dest.is_ssa); nir_foreach_phi_src(src, phi) { + if (nir_src_is_undef(src->src)) + continue; + nir_parallel_copy_instr *pcopy = get_parallel_copy_at_end_of_block(src->pred); assert(pcopy); @@ -460,6 +463,9 @@ coalesce_phi_nodes_block(nir_block *block, struct from_ssa_state *state) nir_foreach_phi_src(src, phi) { assert(src->src.is_ssa); + if (nir_src_is_undef(src->src)) + continue; + merge_node *src_node = get_merge_node(src->src.ssa, state); if (src_node->set != dest_node->set) merge_merge_sets(dest_node->set, src_node->set);