From 4ca3cc5a1ac0162ae012b7d4c4c4fc75776eb80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Fri, 25 Jul 2025 10:18:28 +0200 Subject: [PATCH] aco/ra: propagate precolor affinities through parallelcopies and tied definitions Totals from 214 (0.27% of 79839) affected shaders: (Navi48) Instrs: 65339 -> 65311 (-0.04%); split: -0.05%, +0.00% CodeSize: 352616 -> 350952 (-0.47%); split: -0.55%, +0.07% VGPRs: 9984 -> 9960 (-0.24%) Latency: 207556 -> 207508 (-0.02%); split: -0.03%, +0.01% InvThroughput: 40422 -> 40397 (-0.06%) Copies: 3180 -> 3155 (-0.79%) VALU: 38347 -> 38322 (-0.07%) Part-of: --- src/amd/compiler/aco_register_allocation.cpp | 46 ++++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/amd/compiler/aco_register_allocation.cpp b/src/amd/compiler/aco_register_allocation.cpp index 33c23bfe85c..9fb67e9f7ed 100644 --- a/src/amd/compiler/aco_register_allocation.cpp +++ b/src/amd/compiler/aco_register_allocation.cpp @@ -3112,26 +3112,34 @@ get_affinities(ra_ctx& ctx) const Definition& def = instr->definitions[i]; if (!def.isTemp()) continue; - /* mark last-seen phi operand */ - auto it = temp_to_phi_resources.find(def.tempId()); - if (it != temp_to_phi_resources.end() && - def.regClass() == phi_resources[it->second][0].regClass()) { - phi_resources[it->second][0] = def.getTemp(); - /* try to coalesce phi affinities with parallelcopies */ - Operand op; - if (instr->opcode == aco_opcode::p_parallelcopy) { - op = instr->operands[i]; - } else if (i < tied_defs.size()) { - op = instr->operands[tied_defs[i]]; - } else if (vop3_can_use_vop2acc(ctx, instr.get())) { - op = instr->operands[2]; - } else if (i == 0 && sop2_can_use_sopk(ctx, instr.get())) { - op = instr->operands[instr->operands[0].isLiteral()]; - } else { - continue; - } - if (op.isTemp() && op.isFirstKillBeforeDef() && def.regClass() == op.regClass()) { + auto it = temp_to_phi_resources.find(def.tempId()); + if (it != temp_to_phi_resources.end()) { + /* mark last-seen phi operand */ + phi_resources[it->second][0] = def.getTemp(); + } else if (!ctx.assignments[def.tempId()].precolor_affinity) { + continue; + } + + /* try to coalesce affinities with parallelcopies */ + Operand op; + if (instr->opcode == aco_opcode::p_parallelcopy) { + op = instr->operands[i]; + } else if (i < tied_defs.size()) { + op = instr->operands[tied_defs[i]]; + } else if (vop3_can_use_vop2acc(ctx, instr.get())) { + op = instr->operands[2]; + } else if (i == 0 && sop2_can_use_sopk(ctx, instr.get())) { + op = instr->operands[instr->operands[0].isLiteral()]; + } else { + continue; + } + + if (op.isTemp() && op.isFirstKillBeforeDef() && def.regClass() == op.regClass()) { + if (ctx.assignments[def.tempId()].precolor_affinity) + ctx.assignments[op.tempId()].set_precolor_affinity( + ctx.assignments[def.tempId()].reg); + if (it != temp_to_phi_resources.end()) { phi_resources[it->second].emplace_back(op.getTemp()); temp_to_phi_resources[op.tempId()] = it->second; }