From 7af0dcbdfc895178b0ae0cd37fd80198e1316fc8 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Thu, 17 Aug 2023 16:38:09 -0500 Subject: [PATCH] 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 Part-of: --- src/compiler/nir/nir_opt_undef.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/compiler/nir/nir_opt_undef.c b/src/compiler/nir/nir_opt_undef.c index 8a5c71f..08d7fdc 100644 --- a/src/compiler/nir/nir_opt_undef.c +++ b/src/compiler/nir/nir_opt_undef.c @@ -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); -- 2.7.4