From dd765da872d6ad93148072285d47cf9137c2553c Mon Sep 17 00:00:00 2001 From: Vasily Khoruzhick Date: Tue, 25 Feb 2025 23:14:23 -0800 Subject: [PATCH] lima: ppir: try inserting nodes into successor instr for uncond branch It is safe to attempt inserting a node into the same instruction as successor if successor is an unconditional branch. ppir_instr_insert_node() will take care of conflicts with ALU_COMBINE slot Reviewed-by: Erico Nunes Signed-off-by: Vasily Khoruzhick Part-of: --- src/gallium/drivers/lima/ir/pp/instr.c | 7 +++++++ src/gallium/drivers/lima/ir/pp/node_to_instr.c | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/gallium/drivers/lima/ir/pp/instr.c b/src/gallium/drivers/lima/ir/pp/instr.c index 974d646a952..0befd2cd21a 100644 --- a/src/gallium/drivers/lima/ir/pp/instr.c +++ b/src/gallium/drivers/lima/ir/pp/instr.c @@ -238,6 +238,13 @@ bool ppir_instr_insert_node(ppir_instr *instr, ppir_node *node) } } + if (pos == PPIR_INSTR_SLOT_BRANCH) { + /* Branch and combiner run in parallel, they cannot be inserted + * into the same instruction */ + if (instr->slots[PPIR_INSTR_SLOT_ALU_COMBINE]) + return false; + } + if (pos == PPIR_INSTR_SLOT_ALU_VEC_MUL) { if (dest && dest->type == ppir_target_pipeline) { ppir_node *add = ppir_node_first_succ(node); diff --git a/src/gallium/drivers/lima/ir/pp/node_to_instr.c b/src/gallium/drivers/lima/ir/pp/node_to_instr.c index e76a5e2aae6..a0288463e36 100644 --- a/src/gallium/drivers/lima/ir/pp/node_to_instr.c +++ b/src/gallium/drivers/lima/ir/pp/node_to_instr.c @@ -121,6 +121,17 @@ static bool ppir_do_one_node_to_instr(ppir_block *block, ppir_node *node) } + if (!node->instr && + ppir_node_has_single_succ(node)) { + ppir_node *succ = ppir_node_first_succ(node); + if (succ->op == ppir_op_branch && + ppir_node_get_src_num(succ) == 0 && + succ->instr) { + /* Unconditional branch. Likely a loop */ + ppir_instr_insert_node(succ->instr, node); + } + } + /* can't inserted to any existing instr, create one */ if (!node->instr && !create_new_instr(block, node)) return false;