From fdeabf416235af3c76c01e33070cbb55df136209 Mon Sep 17 00:00:00 2001 From: Vasily Khoruzhick Date: Sun, 23 Feb 2025 21:40:00 -0800 Subject: [PATCH] lima: ppir: reuse uniform load in instruction if possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Vasily Khoruzhick Part-of: --- src/gallium/drivers/lima/ir/pp/instr.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/lima/ir/pp/instr.c b/src/gallium/drivers/lima/ir/pp/instr.c index 1dca40286d3..974d646a952 100644 --- a/src/gallium/drivers/lima/ir/pp/instr.c +++ b/src/gallium/drivers/lima/ir/pp/instr.c @@ -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) {