From 2619d576e77da1fe9396e5170947055c903ce9d9 Mon Sep 17 00:00:00 2001 From: Job Noorman Date: Thu, 27 Feb 2025 13:50:59 +0100 Subject: [PATCH] nir/lower_phis_to_scalar: don't create moves for undef sources Creating moves out of undefs makes it more difficult for other passes to detects undefs without having to chase moves. Instead, just create a new 1-component undef. Signed-off-by: Job Noorman Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_lower_phis_to_scalar.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/compiler/nir/nir_lower_phis_to_scalar.c b/src/compiler/nir/nir_lower_phis_to_scalar.c index 67e8b591fa9..7a96a02db81 100644 --- a/src/compiler/nir/nir_lower_phis_to_scalar.c +++ b/src/compiler/nir/nir_lower_phis_to_scalar.c @@ -208,10 +208,21 @@ lower_phis_to_scalar_block(nir_block *block, vec_srcs[i] = &new_phi->def; nir_foreach_phi_src(src, phi) { - /* We need to insert a mov to grab the i'th component of src */ + nir_def *def; state->builder.cursor = nir_after_block_before_jump(src->pred); - nir_def *mov = nir_channel(&state->builder, src->src.ssa, i); - nir_phi_instr_add_src(new_phi, src->pred, mov); + + if (nir_src_is_undef(src->src)) { + /* Just create a 1-component undef instead of moving out of the + * original one. This makes it easier for other passes to + * detect undefs without having to chase moves. + */ + def = nir_undef(&state->builder, 1, phi->def.bit_size); + } else { + /* We need to insert a mov to grab the i'th component of src */ + def = nir_channel(&state->builder, src->src.ssa, i); + } + + nir_phi_instr_add_src(new_phi, src->pred, def); } nir_instr_insert_before(&phi->instr, &new_phi->instr);