From 83247ffa302a277af7097ac4588e36e71b109224 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Tue, 25 Feb 2025 11:39:33 +0100 Subject: [PATCH] aco/opt_postRA: remove scc != 0 with multiple uses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These can always be removed. Foz-DB Navi21: Totals from 39 (0.05% of 79789) affected shaders: Instrs: 138352 -> 138299 (-0.04%) CodeSize: 710424 -> 710272 (-0.02%) Latency: 468276 -> 468254 (-0.00%); split: -0.01%, +0.00% InvThroughput: 108970 -> 108973 (+0.00%) SALU: 18785 -> 18732 (-0.28%) Reviewed-by: Timur Kristóf Part-of: --- src/amd/compiler/aco_optimizer_postRA.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/amd/compiler/aco_optimizer_postRA.cpp b/src/amd/compiler/aco_optimizer_postRA.cpp index f6fc4ec260d..95a3efa4f32 100644 --- a/src/amd/compiler/aco_optimizer_postRA.cpp +++ b/src/amd/compiler/aco_optimizer_postRA.cpp @@ -448,16 +448,16 @@ try_optimize_scc_nocompare(pr_opt_ctx& ctx, aco_ptr& instr) /* Check if we found the pattern above. */ if (wr_instr->opcode != aco_opcode::s_cmp_eq_u32 && wr_instr->opcode != aco_opcode::s_cmp_lg_u32) return; - if (wr_instr->operands[0].physReg() != scc) + if (wr_instr->operands[0].physReg() != scc || !wr_instr->operands[0].isTemp()) return; if (!wr_instr->operands[1].constantEquals(0)) return; - /* The optimization can be unsafe when there are other users. */ - if (ctx.uses[instr->operands[scc_op_idx].tempId()] > 1) - return; - if (wr_instr->opcode == aco_opcode::s_cmp_eq_u32) { + /* The optimization can be unsafe when there are other users. */ + if (ctx.uses[instr->operands[scc_op_idx].tempId()] > 1) + return; + /* Flip the meaning of the instruction to correctly use the SCC. */ if (instr->format == Format::PSEUDO_BRANCH) instr->opcode = instr->opcode == aco_opcode::p_cbranch_z ? aco_opcode::p_cbranch_nz @@ -471,6 +471,8 @@ try_optimize_scc_nocompare(pr_opt_ctx& ctx, aco_ptr& instr) /* Use the SCC def from the original instruction, not the comparison */ ctx.uses[instr->operands[scc_op_idx].tempId()]--; + if (ctx.uses[instr->operands[scc_op_idx].tempId()]) + ctx.uses[wr_instr->operands[0].tempId()]++; instr->operands[scc_op_idx] = wr_instr->operands[0]; }