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 2556 (3.20% of 79825) affected shaders:
MaxWaves: 59957 -> 59955 (-0.00%)
Instrs: 9170941 -> 9154954 (-0.17%); split: -0.19%, +0.02%
CodeSize: 48245956 -> 48182620 (-0.13%); split: -0.15%, +0.02%
VGPRs: 189372 -> 189900 (+0.28%); split: -0.04%, +0.32%
Latency: 85469322 -> 85262360 (-0.24%); split: -0.32%, +0.08%
InvThroughput: 14515911 -> 14486970 (-0.20%); split: -0.27%, +0.07%
VClause: 197980 -> 197959 (-0.01%); split: -0.02%, +0.01%
Copies: 787838 -> 774288 (-1.72%); split: -1.91%, +0.19%
Branches: 271810 -> 271799 (-0.00%); split: -0.01%, +0.01%
VALU: 5331813 -> 5318566 (-0.25%); split: -0.28%, +0.03%
SALU: 1133559 -> 1133054 (-0.04%); split: -0.05%, +0.01%
VOPD: 2435 -> 2418 (-0.70%); split: +0.12%, -0.82%

fossil-db (navi21):
Totals from 37513 (46.99% of 79825) affected shaders:
Instrs: 26734825 -> 26681225 (-0.20%); split: -0.23%, +0.03%
CodeSize: 141353284 -> 141144360 (-0.15%); split: -0.17%, +0.02%
VGPRs: 1556760 -> 1556384 (-0.02%); split: -0.21%, +0.18%
Latency: 146201548 -> 146156473 (-0.03%); split: -0.20%, +0.17%
InvThroughput: 33921803 -> 33867398 (-0.16%); split: -0.23%, +0.07%
VClause: 502263 -> 502209 (-0.01%); split: -0.27%, +0.26%
SClause: 593142 -> 593155 (+0.00%); split: -0.00%, +0.00%
Copies: 2600995 -> 2551257 (-1.91%); split: -2.16%, +0.25%
Branches: 857910 -> 857787 (-0.01%); split: -0.03%, +0.02%
VALU: 15674532 -> 15625013 (-0.32%); split: -0.35%, +0.04%
SALU: 4635548 -> 4634680 (-0.02%); split: -0.04%, +0.02%

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38262>
This commit is contained in:
Rhys Perry 2025-10-29 12:56:51 +00:00 committed by Marge Bot
parent 86f0195f5c
commit f81aaee7f1

View file

@ -3442,6 +3442,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<uint32_t, Instruction*> 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