From 6445ba0f05aeba369946c52debce3d617bec2390 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Tue, 25 Feb 2025 11:36:00 +0100 Subject: [PATCH] aco/opt_postRA: allow try_optimize_scc_nocompare for all instructions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the old SCC source worked, the new one will too. Foz-DB Navi21: Totals from 106 (0.13% of 79789) affected shaders: Instrs: 255233 -> 254825 (-0.16%) CodeSize: 1337308 -> 1335692 (-0.12%) Latency: 1455208 -> 1454524 (-0.05%); split: -0.05%, +0.00% InvThroughput: 385624 -> 385612 (-0.00%); split: -0.00%, +0.00% SALU: 53976 -> 53568 (-0.76%) Reviewed-by: Timur Kristóf Part-of: --- src/amd/compiler/aco_optimizer_postRA.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/amd/compiler/aco_optimizer_postRA.cpp b/src/amd/compiler/aco_optimizer_postRA.cpp index 2325b37c503..f6fc4ec260d 100644 --- a/src/amd/compiler/aco_optimizer_postRA.cpp +++ b/src/amd/compiler/aco_optimizer_postRA.cpp @@ -428,17 +428,17 @@ try_optimize_scc_nocompare(pr_opt_ctx& ctx, aco_ptr& instr) * s_cbranch_scc1 BB3 ; inverted branch */ - if ((instr->format != Format::PSEUDO_BRANCH || instr->operands.size() != 1 || - instr->operands[0].physReg() != scc) && - instr->opcode != aco_opcode::s_cselect_b32 && instr->opcode != aco_opcode::s_cselect_b64) - return; - - /* For cselect, operand 2 is the SCC condition */ - unsigned scc_op_idx = 0; - if (instr->opcode == aco_opcode::s_cselect_b32 || instr->opcode == aco_opcode::s_cselect_b64) { - scc_op_idx = 2; + int scc_op_idx = -1; + for (unsigned i = 0; i < instr->operands.size(); i++) { + if (instr->operands[i].isTemp() && instr->operands[i].physReg() == scc) { + scc_op_idx = i; + break; + } } + if (scc_op_idx < 0) + return; + Idx wr_idx = last_writer_idx(ctx, instr->operands[scc_op_idx]); if (!wr_idx.found()) return; @@ -466,7 +466,7 @@ try_optimize_scc_nocompare(pr_opt_ctx& ctx, aco_ptr& instr) instr->opcode == aco_opcode::s_cselect_b64) std::swap(instr->operands[0], instr->operands[1]); else - unreachable("scc_nocompare optimization is only implemented for p_cbranch and s_cselect"); + return; } /* Use the SCC def from the original instruction, not the comparison */