From 022705b03acb1c0837117fdfd2446b4c445734ab Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Wed, 29 Oct 2025 12:56:51 +0000 Subject: [PATCH] aco/ra: create vectors for affinities of split definitions For example: a = ... b = ... if { c, d = split } phi(a, c) phi(b, d) This patch will allocate 'a' and 'b' as a vector. fossil-db (navi31): Totals from 2566 (3.21% of 79825) affected shaders: MaxWaves: 59941 -> 59939 (-0.00%) Instrs: 9160792 -> 9146435 (-0.16%); split: -0.18%, +0.02% CodeSize: 48178860 -> 48122308 (-0.12%); split: -0.14%, +0.02% VGPRs: 189756 -> 190320 (+0.30%); split: -0.04%, +0.34% Latency: 85163405 -> 84972598 (-0.22%); split: -0.29%, +0.07% InvThroughput: 14490059 -> 14464958 (-0.17%); split: -0.23%, +0.06% VClause: 197594 -> 197639 (+0.02%); split: -0.01%, +0.03% Copies: 794103 -> 781555 (-1.58%); split: -1.81%, +0.23% Branches: 271605 -> 271592 (-0.00%); split: -0.02%, +0.01% VALU: 5330323 -> 5318069 (-0.23%); split: -0.26%, +0.03% SALU: 1130031 -> 1129658 (-0.03%); split: -0.05%, +0.01% VOPD: 2511 -> 2503 (-0.32%); split: +0.48%, -0.80% fossil-db (navi21): Totals from 37512 (46.99% of 79825) affected shaders: Instrs: 26725535 -> 26672372 (-0.20%); split: -0.22%, +0.03% CodeSize: 141296848 -> 141075516 (-0.16%); split: -0.18%, +0.02% VGPRs: 1556584 -> 1556216 (-0.02%); split: -0.21%, +0.19% Latency: 146266991 -> 146202343 (-0.04%); split: -0.20%, +0.16% InvThroughput: 33932575 -> 33872374 (-0.18%); split: -0.23%, +0.06% VClause: 501929 -> 501949 (+0.00%); split: -0.27%, +0.27% SClause: 592642 -> 592655 (+0.00%); split: -0.00%, +0.00% Copies: 2600040 -> 2550475 (-1.91%); split: -2.16%, +0.25% Branches: 857553 -> 857465 (-0.01%); split: -0.03%, +0.02% VALU: 15668495 -> 15619140 (-0.31%); split: -0.35%, +0.04% SALU: 4634670 -> 4633930 (-0.02%); split: -0.03%, +0.02% Signed-off-by: Rhys Perry --- src/amd/compiler/aco_register_allocation.cpp | 45 ++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/amd/compiler/aco_register_allocation.cpp b/src/amd/compiler/aco_register_allocation.cpp index 3c4b029c058..c4b1e5515e3 100644 --- a/src/amd/compiler/aco_register_allocation.cpp +++ b/src/amd/compiler/aco_register_allocation.cpp @@ -3347,6 +3347,51 @@ get_affinities(ra_ctx& ctx) ctx.vectors[vec[0].id()] = it->second; } } + + /* If split definitions have affinities with other temporaries, try to allocate those temporaries + * as a vector. */ + for (std::pair pair : ctx.split_vectors) { + Instruction *split = pair.second; + + vector_info info; + info.num_parts = split->definitions.size(); + + unsigned num_temps = 0; + for (unsigned i = 0; i < split->definitions.size(); i++) { + Definition def = split->definitions[i]; + uint32_t id = ctx.assignments[def.tempId()].affinity; + if (!id || def.regClass().type() != split->operands[0].regClass().type()) + continue; + + if (!info.parts) { + info.parts = + (Operand*)ctx.memory.allocate(sizeof(Operand) * info.num_parts, alignof(Operand)); + for (unsigned j = 0; j < split->definitions.size(); j++) + info.parts[j] = Operand(split->definitions[j].regClass()); + } + + info.parts[i] = Operand(Temp(id, ctx.program->temp_rc[id])); + num_temps++; + } + if (!num_temps) + continue; + + for (unsigned i = 0; i < split->definitions.size(); i++) { + uint32_t id = info.parts[i].tempId(); + if (!id) + continue; + + /* If the new vector affinities only includes one temporary, only overwrite the old one if + * the new one is stronger. */ + auto vec_it = ctx.vectors.find(id); + if (num_temps == 1 && vec_it != ctx.vectors.end() && + (!vec_it->second.is_weak || info.is_weak)) + continue; + + info.index = i; + ctx.vectors[id] = info; + } + } } void