From e25c182993c61671bc993cb74ef662b0441790a8 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 6 Apr 2023 17:13:45 -0400 Subject: [PATCH] nir: Use nir_src_rewrite_ssa Where sensible. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Faith Ekstrand Part-of: --- src/compiler/nir/nir.c | 16 +++++++--------- src/compiler/nir/nir_opt_copy_propagate.c | 17 ++--------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index ef407df32f3..cb6ceb4f671 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -1743,10 +1743,7 @@ nir_ssa_def_rewrite_uses(nir_ssa_def *def, nir_ssa_def *new_ssa) { assert(def != new_ssa); nir_foreach_use_including_if_safe(use_src, def) { - if (use_src->is_if) - nir_if_rewrite_condition_ssa(use_src->parent_if, use_src, new_ssa); - else - nir_instr_rewrite_src_ssa(use_src->parent_instr, use_src, new_ssa); + nir_src_rewrite_ssa(use_src, new_ssa); } } @@ -1803,17 +1800,18 @@ nir_ssa_def_rewrite_uses_after(nir_ssa_def *def, nir_ssa_def *new_ssa, return; nir_foreach_use_including_if_safe(use_src, def) { - if (use_src->is_if) { - nir_if_rewrite_condition_ssa(use_src->parent_if, use_src, new_ssa); - } else { + if (!use_src->is_if) { assert(use_src->parent_instr != def->parent_instr); + /* Since def already dominates all of its uses, the only way a use can * not be dominated by after_me is if it is between def and after_me in * the instruction list. */ - if (!is_instr_between(def->parent_instr, after_me, use_src->parent_instr)) - nir_instr_rewrite_src_ssa(use_src->parent_instr, use_src, new_ssa); + if (is_instr_between(def->parent_instr, after_me, use_src->parent_instr)) + continue; } + + nir_src_rewrite_ssa(use_src, new_ssa); } } diff --git a/src/compiler/nir/nir_opt_copy_propagate.c b/src/compiler/nir/nir_opt_copy_propagate.c index 70c0733df0f..6fc294657d1 100644 --- a/src/compiler/nir/nir_opt_copy_propagate.c +++ b/src/compiler/nir/nir_opt_copy_propagate.c @@ -117,18 +117,7 @@ copy_propagate(nir_src *src, nir_alu_instr *copy) if (!is_swizzleless_move(copy)) return false; - nir_instr_rewrite_src_ssa(src->parent_instr, src, copy->src[0].src.ssa); - - return true; -} - -static bool -copy_propagate_if(nir_src *src, nir_alu_instr *copy) -{ - if (!is_swizzleless_move(copy)) - return false; - - nir_if_rewrite_condition_ssa(src->parent_if, src, copy->src[0].src.ssa); + nir_src_rewrite_ssa(src, copy->src[0].src.ssa); return true; } @@ -147,9 +136,7 @@ copy_prop_instr(nir_function_impl *impl, nir_instr *instr) bool progress = false; nir_foreach_use_including_if_safe(src, &mov->dest.dest.ssa) { - if (src->is_if) - progress |= copy_propagate_if(src, mov); - else if (src->parent_instr->type == nir_instr_type_alu) + if (!src->is_if && src->parent_instr->type == nir_instr_type_alu) progress |= copy_propagate_alu(impl, container_of(src, nir_alu_src, src), mov); else progress |= copy_propagate(src, mov);