From f783f5df6d3abeadaafff3dda57416ce0477a48f Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Thu, 17 Apr 2025 16:02:42 +0100 Subject: [PATCH] aco/ra: move optimize_encoding earlier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have to handle tied definitions after optimize_encoding, but a rewrite of that will need the register file from before clearing the killed operands. Signed-off-by: Rhys Perry Reviewed-by: Daniel Schürmann Part-of: --- src/amd/compiler/aco_register_allocation.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/amd/compiler/aco_register_allocation.cpp b/src/amd/compiler/aco_register_allocation.cpp index 0afa53da51f..07e3417fd79 100644 --- a/src/amd/compiler/aco_register_allocation.cpp +++ b/src/amd/compiler/aco_register_allocation.cpp @@ -3009,7 +3009,9 @@ optimize_encoding_vop2(ra_ctx& ctx, RegisterFile& register_file, aco_ptroperands[2].physReg() && - !register_file.test(affinity.reg, instr->operands[2].bytes())) + (!register_file.test(affinity.reg, instr->operands[2].bytes()) || + std::any_of(instr->operands.begin(), instr->operands.end(), [&](Operand op) + { return op.isKillBeforeDef() && op.physReg() == affinity.reg; }))) return; } @@ -3057,7 +3059,9 @@ optimize_encoding_sopk(ra_ctx& ctx, RegisterFile& register_file, aco_ptroperands[!literal_idx].physReg() && - !register_file.test(affinity.reg, instr->operands[!literal_idx].bytes())) + (!register_file.test(affinity.reg, instr->operands[!literal_idx].bytes()) || + std::any_of(instr->operands.begin(), instr->operands.end(), [&](Operand op) + { return op.isKillBeforeDef() && op.physReg() == affinity.reg; }))) return; } @@ -3315,14 +3319,14 @@ register_allocation(Program* program, ra_test_policy policy) } bool temp_in_scc = register_file[scc]; + optimize_encoding(ctx, register_file, instr); + /* remove dead vars from register file */ for (const Operand& op : instr->operands) { if (op.isTemp() && op.isFirstKillBeforeDef()) register_file.clear(op); } - optimize_encoding(ctx, register_file, instr); - /* Handle definitions which must have the same register as an operand. * We expect that the definition has the same size as the operand, otherwise the new * location for the operand (if it's not killed) might intersect with the old one.