From 24c60be1adc5ec089f9784593803cb719ec389f0 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Tue, 24 Sep 2024 14:51:51 +0100 Subject: [PATCH] aco: create vector affinities for phi operands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fossil-db (navi21): Totals from 2934 (3.70% of 79395) affected shaders: Instrs: 8368484 -> 8365630 (-0.03%); split: -0.05%, +0.01% CodeSize: 46032152 -> 45998480 (-0.07%); split: -0.09%, +0.01% VGPRs: 200360 -> 200280 (-0.04%); split: -0.12%, +0.08% Latency: 85556147 -> 85562615 (+0.01%); split: -0.09%, +0.10% InvThroughput: 19066462 -> 19065173 (-0.01%); split: -0.09%, +0.09% VClause: 209834 -> 209783 (-0.02%); split: -0.14%, +0.12% SClause: 261811 -> 261826 (+0.01%); split: -0.00%, +0.01% Copies: 727502 -> 724394 (-0.43%); split: -0.56%, +0.13% Branches: 291083 -> 291120 (+0.01%); split: -0.01%, +0.03% VALU: 5564021 -> 5560975 (-0.05%); split: -0.07%, +0.02% SALU: 1100996 -> 1100942 (-0.00%); split: -0.02%, +0.02% fossil-db (navi31): Totals from 34207 (43.08% of 79395) affected shaders: MaxWaves: 1036893 -> 1036781 (-0.01%); split: +0.01%, -0.02% Instrs: 21977229 -> 21884600 (-0.42%); split: -0.47%, +0.05% CodeSize: 112680884 -> 112298404 (-0.34%); split: -0.38%, +0.04% VGPRs: 1590832 -> 1615912 (+1.58%); split: -0.25%, +1.83% Latency: 142542601 -> 142670271 (+0.09%); split: -0.12%, +0.21% InvThroughput: 19481055 -> 19434110 (-0.24%); split: -0.44%, +0.20% VClause: 462865 -> 462558 (-0.07%); split: -0.20%, +0.13% SClause: 619822 -> 619685 (-0.02%); split: -0.02%, +0.00% Copies: 1704870 -> 1610889 (-5.51%); split: -5.89%, +0.38% Branches: 518238 -> 518241 (+0.00%); split: -0.01%, +0.01% VALU: 12230157 -> 12136112 (-0.77%); split: -0.82%, +0.05% SALU: 2444075 -> 2444099 (+0.00%); split: -0.01%, +0.01% VOPD: 3443 -> 3476 (+0.96%); split: +1.80%, -0.84% Signed-off-by: Rhys Perry Reviewed-by: Daniel Schürmann Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11186 Part-of: --- src/amd/compiler/aco_register_allocation.cpp | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/amd/compiler/aco_register_allocation.cpp b/src/amd/compiler/aco_register_allocation.cpp index e42d4d3b9ca..c956782ddb6 100644 --- a/src/amd/compiler/aco_register_allocation.cpp +++ b/src/amd/compiler/aco_register_allocation.cpp @@ -2634,6 +2634,46 @@ sop2_can_use_sopk(ra_ctx& ctx, Instruction* instr) return true; } +void +create_phi_vector_affinities(ra_ctx& ctx, aco_ptr& instr, + std::map>& vector_phis) +{ + auto it = ctx.vectors.find(instr->definitions[0].tempId()); + if (it == ctx.vectors.end()) + return; + vector_info& dest_vector = it->second; + + auto pair = vector_phis.try_emplace(dest_vector.parts, instr->operands.size(), dest_vector); + std::vector& src_vectors = pair.first->second; + if (pair.second) { + RegType type = instr->definitions[0].regClass().type(); + + for (vector_info& src_vector : src_vectors) { + src_vector.parts = + (Operand*)ctx.memory.allocate(sizeof(Operand) * src_vector.num_parts, alignof(Operand)); + for (unsigned j = 0; j < src_vector.num_parts; j++) + src_vector.parts[j] = Operand(RegClass::get(type, dest_vector.parts[j].bytes())); + } + } + + unsigned index = 0; + for (; index < dest_vector.num_parts; index++) { + if (dest_vector.parts[index].isTemp() && + dest_vector.parts[index].tempId() == instr->definitions[0].tempId()) + break; + } + assert(index != dest_vector.num_parts); + + for (int i = instr->operands.size() - 1; i >= 0; i--) { + const Operand& op = instr->operands[i]; + if (!op.isTemp() || op.regClass() != instr->definitions[0].regClass()) + continue; + + src_vectors[i].parts[index] = op; + ctx.vectors[op.tempId()] = src_vectors[i]; + } +} + void get_affinities(ra_ctx& ctx) { @@ -2718,6 +2758,7 @@ get_affinities(ra_ctx& ctx) } /* collect phi affinities */ + std::map> vector_phis; for (; rit != block.instructions.rend(); ++rit) { aco_ptr& instr = *rit; assert(is_phi(instr)); @@ -2746,6 +2787,8 @@ get_affinities(ra_ctx& ctx) temp_to_phi_resources[op.tempId()] = index; } } + + create_phi_vector_affinities(ctx, instr, vector_phis); } /* visit the loop header phis first in order to create nested affinities */