From 9e8ba10447f08ee757f6a4719ff23960a2b18c6b Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Mon, 7 Jul 2025 13:19:33 +0200 Subject: [PATCH] aco/vn: remove dead instructions early MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dead p_create_vector/p_split_vector left behind by instruction selection slow down the other passes and negatively affect extract labels in aco_optimizer. Foz-DB GFX1201: Totals from 964 (1.20% of 80251) affected shaders: MaxWaves: 29206 -> 29030 (-0.60%); split: +0.08%, -0.68% Instrs: 669369 -> 668842 (-0.08%); split: -0.16%, +0.09% CodeSize: 3385192 -> 3383216 (-0.06%); split: -0.13%, +0.07% VGPRs: 46788 -> 46848 (+0.13%); split: -0.85%, +0.97% Latency: 3985660 -> 3892742 (-2.33%); split: -2.54%, +0.21% InvThroughput: 538296 -> 536761 (-0.29%); split: -0.38%, +0.10% VClause: 8336 -> 8418 (+0.98%); split: -0.17%, +1.15% SClause: 17111 -> 17120 (+0.05%); split: -0.20%, +0.25% Copies: 44393 -> 44239 (-0.35%); split: -1.25%, +0.91% PreSGPRs: 45417 -> 45419 (+0.00%) PreVGPRs: 30401 -> 31644 (+4.09%); split: -0.00%, +4.09% VALU: 348282 -> 348167 (-0.03%); split: -0.15%, +0.12% SALU: 121454 -> 121410 (-0.04%); split: -0.04%, +0.01% Reviewed-by: Daniel Schürmann Part-of: --- src/amd/compiler/aco_opt_value_numbering.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/amd/compiler/aco_opt_value_numbering.cpp b/src/amd/compiler/aco_opt_value_numbering.cpp index 5fa61e72bb4..45d9847ac00 100644 --- a/src/amd/compiler/aco_opt_value_numbering.cpp +++ b/src/amd/compiler/aco_opt_value_numbering.cpp @@ -239,6 +239,7 @@ struct vn_ctx { monotonic_buffer_resource m; expr_set expr_values; aco::unordered_map renames; + std::vector uses; /* The exec id should be the same on the same level of control flow depth. * Together with the check for dominator relations, it is safe to assume @@ -254,6 +255,7 @@ struct vn_ctx { for (Block& block : program->blocks) size += block.instructions.size(); expr_values.reserve(size); + uses = dead_code_analysis(program); } }; @@ -342,6 +344,10 @@ process_block(vn_ctx& ctx, Block& block) new_instructions.reserve(block.instructions.size()); for (aco_ptr& instr : block.instructions) { + /* Clean up dead create_vector/split_vector left behind by instruction selection. */ + if (is_dead(ctx.uses, instr.get())) + continue; + /* first, rename operands */ for (Operand& op : instr->operands) { if (!op.isTemp())