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 <jnoorman@igalia.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29889>
This commit is contained in:
Job Noorman 2025-02-27 13:50:59 +01:00 committed by Marge Bot
parent 5ae12b6a5a
commit 2619d576e7

View file

@ -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);