From 223af79274c4062e977e2fcd36fe8dbf3a582ae1 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Wed, 25 Feb 2026 13:05:35 +0000 Subject: [PATCH] aco: perform dce for blocks skipped for process_block() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We might need to DCE users of dead instructions removed by process_block(). Signed-off-by: Rhys Perry Fixes: 9e8ba10447f0 ("aco/vn: remove dead instructions early") Reviewed-by: Daniel Schürmann (cherry picked from commit 17b18496f6bd0e3a425b9ff09b6cf843de787b31) Part-of: --- .pick_status.json | 2 +- src/amd/compiler/aco_opt_value_numbering.cpp | 21 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index ed59eba0199..bd00c0b978a 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -4374,7 +4374,7 @@ "description": "aco: perform dce for blocks skipped for process_block()", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "9e8ba10447f08ee757f6a4719ff23960a2b18c6b", "notes": null diff --git a/src/amd/compiler/aco_opt_value_numbering.cpp b/src/amd/compiler/aco_opt_value_numbering.cpp index dfd8c1e3891..9f867e2e0af 100644 --- a/src/amd/compiler/aco_opt_value_numbering.cpp +++ b/src/amd/compiler/aco_opt_value_numbering.cpp @@ -427,6 +427,21 @@ process_block(vn_ctx& ctx, Block& block) block.instructions = std::move(new_instructions); } +void +dce_instructions(vn_ctx& ctx, Block& block) +{ + std::vector> new_instructions; + new_instructions.reserve(block.instructions.size()); + + for (aco_ptr& instr : block.instructions) { + if (is_dead(ctx.uses, instr.get())) + continue; + new_instructions.emplace_back(std::move(instr)); + } + + block.instructions = std::move(new_instructions); +} + void rename_phi_operands(Block& block, aco::unordered_map& renames) { @@ -467,10 +482,12 @@ value_numbering(Program* program) if (block.logical_idom == (int)block.index) ctx.expr_values.clear(); - if (block.logical_idom != -1) + if (block.logical_idom != -1) { process_block(ctx, block); - else + } else { + dce_instructions(ctx, block); rename_phi_operands(block, ctx.renames); + } /* increment exec_id when entering nested control flow */ if (block.kind & block_kind_branch || block.kind & block_kind_loop_preheader ||