lima: ppir: reuse uniform load in instruction if possible

We clone loads for uniforms for each user, which means that each
ppir_node will have its own, however an instruction may have several
nodes that need to load uniforms. Currently, in this case ppir compiler
will place all but one load uniforms nodes into a new instruction and
create an extra mov.

We can optimize that by checking whether load_uniform node in the instruction
is the same as the one we are trying to insert and reuse it. It is safe
to do so, because successors use pipeline register, so regalloc doesn't
care about it.

shader-db:

total instructions in shared programs: 27808 -> 27718 (-0.32%)
instructions in affected programs: 2652 -> 2562 (-3.39%)
helped: 31
HURT: 0
helped stats (abs) min: 1 max: 8 x̄: 2.90 x̃: 2
helped stats (rel) min: 0.56% max: 33.33% x̄: 5.12% x̃: 4.11%
95% mean confidence interval for instructions value: -3.78 -2.03
95% mean confidence interval for instructions %-change: -7.24% -2.99%
Instructions are helped.

total loops in shared programs: 4 -> 4 (0.00%)
loops in affected programs: 0 -> 0
helped: 0
HURT: 0

total spills in shared programs: 391 -> 390 (-0.26%)
spills in affected programs: 1 -> 0
helped: 1
HURT: 0

total fills in shared programs: 1213 -> 1210 (-0.25%)
fills in affected programs: 3 -> 0
helped: 1
HURT: 0

LOST:   0
GAINED: 0

Reviewed-by: Erico Nunes <nunes.erico@gmail.com>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33746>
This commit is contained in:
Vasily Khoruzhick
2025-02-23 21:40:00 -08:00
committed by Marge Bot
parent 20dd6dfa12
commit fdeabf4162
+15 -1
View File
@@ -220,8 +220,22 @@ bool ppir_instr_insert_node(ppir_instr *instr, ppir_node *node)
/* node already in this instr, i.e. load_uniform */
if (instr->slots[pos] == node)
return true;
else
else {
if (pos == PPIR_INSTR_SLOT_UNIFORM && node->op == ppir_op_load_uniform) {
ppir_load_node *load = ppir_node_to_load(node);
ppir_load_node *existing = ppir_node_to_load(instr->slots[PPIR_INSTR_SLOT_UNIFORM]);
if (!load->num_src && !existing->num_src &&
load->index == existing->index &&
load->num_components == existing->num_components) {
ppir_debug("Re-using uniform slot of instr %d with node %d for node %d\n",
instr->index, node->index, existing->node.index);
node->instr = instr;
return true;
}
}
continue;
}
}
if (pos == PPIR_INSTR_SLOT_ALU_VEC_MUL) {