nir/opt_undef: Don't rewrite a bcsel to mov

Technically, it's possible because bcsel has more sources than mov.
However, it's not worth the pain of trying to get it right.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24729>
This commit is contained in:
Faith Ekstrand
2023-08-17 16:38:09 -05:00
committed by Marge Bot
parent 53294de682
commit 7af0dcbdfc
+8 -15
View File
@@ -36,7 +36,7 @@
* each side of the if is defining a variable.
*/
static bool
opt_undef_csel(nir_alu_instr *instr)
opt_undef_csel(nir_builder *b, nir_alu_instr *instr)
{
if (!nir_op_is_selection(instr->op))
return false;
@@ -46,19 +46,10 @@ opt_undef_csel(nir_alu_instr *instr)
if (parent->type != nir_instr_type_undef)
continue;
/* We can't just use nir_alu_src_copy, because we need the def/use
* updated.
*/
nir_instr_rewrite_src(&instr->instr, &instr->src[0].src,
instr->src[i == 1 ? 2 : 1].src);
nir_alu_src_copy(&instr->src[0], &instr->src[i == 1 ? 2 : 1],
instr);
nir_src empty_src;
memset(&empty_src, 0, sizeof(empty_src));
nir_instr_rewrite_src(&instr->instr, &instr->src[1].src, empty_src);
nir_instr_rewrite_src(&instr->instr, &instr->src[2].src, empty_src);
instr->op = nir_op_mov;
b->cursor = nir_instr_remove(&instr->instr);
nir_def *mov = nir_mov_alu(b, instr->src[i == 1 ? 2 : 1],
instr->def.num_components);
nir_def_rewrite_uses(&instr->def, mov);
return true;
}
@@ -183,7 +174,9 @@ nir_opt_undef_instr(nir_builder *b, nir_instr *instr, void *data)
{
if (instr->type == nir_instr_type_alu) {
nir_alu_instr *alu = nir_instr_as_alu(instr);
return opt_undef_csel(alu) || opt_undef_vecN(b, alu) || opt_undef_pack(b, alu);
return opt_undef_csel(b, alu) ||
opt_undef_vecN(b, alu) ||
opt_undef_pack(b, alu);
} else if (instr->type == nir_instr_type_intrinsic) {
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
return opt_undef_store(intrin);