From 0bceb07c03ad92ed38dcb6434a7e3fd7470475f7 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Tue, 15 Jul 2025 16:26:05 +0100 Subject: [PATCH] aco: optimize uniform s_not fossil-db (navi21): Totals from 1442 (1.81% of 79825) affected shaders: Instrs: 2224425 -> 2220624 (-0.17%); split: -0.18%, +0.01% CodeSize: 11778260 -> 11763264 (-0.13%); split: -0.14%, +0.01% Latency: 13396254 -> 13392346 (-0.03%); split: -0.03%, +0.00% InvThroughput: 3145007 -> 3144982 (-0.00%); split: -0.00%, +0.00% SClause: 53037 -> 53035 (-0.00%); split: -0.01%, +0.01% Copies: 185852 -> 184777 (-0.58%); split: -0.71%, +0.13% Branches: 60799 -> 60805 (+0.01%) PreSGPRs: 62940 -> 62954 (+0.02%); split: -0.01%, +0.03% SALU: 298564 -> 294761 (-1.27%); split: -1.34%, +0.06% Signed-off-by: Rhys Perry Reviewed-by: Georg Lehmann Part-of: --- src/amd/compiler/aco_optimizer.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/amd/compiler/aco_optimizer.cpp b/src/amd/compiler/aco_optimizer.cpp index 677d3aa108a..f5f9a76dd28 100644 --- a/src/amd/compiler/aco_optimizer.cpp +++ b/src/amd/compiler/aco_optimizer.cpp @@ -4299,12 +4299,29 @@ to_uniform_bool_instr(opt_ctx& ctx, aco_ptr& instr) case aco_opcode::s_or_b64: instr->opcode = aco_opcode::s_or_b32; break; case aco_opcode::s_xor_b32: case aco_opcode::s_xor_b64: instr->opcode = aco_opcode::s_absdiff_i32; break; + case aco_opcode::s_not_b32: + case aco_opcode::s_not_b64: { + aco_ptr new_instr{ + create_instruction(aco_opcode::s_absdiff_i32, Format::SOP2, 2, 2)}; + new_instr->operands[0] = instr->operands[0]; + new_instr->operands[1] = Operand::c32(1); + new_instr->definitions[0] = instr->definitions[0]; + new_instr->definitions[1] = instr->definitions[1]; + new_instr->pass_flags = instr->pass_flags; + instr = std::move(new_instr); + ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get(); + ctx.info[instr->definitions[1].tempId()].parent_instr = instr.get(); + break; + } default: /* Don't transform other instructions. They are very unlikely to appear here. */ return false; } for (Operand& op : instr->operands) { + if (!op.isTemp()) + continue; + ctx.uses[op.tempId()]--; if (ctx.info[op.tempId()].is_uniform_bool()) { @@ -4330,8 +4347,8 @@ to_uniform_bool_instr(opt_ctx& ctx, aco_ptr& instr) instr->definitions[0].setTemp(Temp(instr->definitions[0].tempId(), s1)); ctx.program->temp_rc[instr->definitions[0].tempId()] = s1; - assert(instr->operands[0].regClass() == s1); - assert(instr->operands[1].regClass() == s1); + assert(!instr->operands[0].isTemp() || instr->operands[0].regClass() == s1); + assert(!instr->operands[1].isTemp() || instr->operands[1].regClass() == s1); return true; }