From 7d9aca2235ab7cbfe98ad54b877852370c7e6cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 28 Jun 2025 01:29:48 -0400 Subject: [PATCH] nir/group_loads: allow moving loads across instructions without defs It wouldn't group these: load (reordeable) store load (reordeable) Acked-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_group_loads.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/compiler/nir/nir_group_loads.c b/src/compiler/nir/nir_group_loads.c index 64942bf6d55..027eb43a1ff 100644 --- a/src/compiler/nir/nir_group_loads.c +++ b/src/compiler/nir/nir_group_loads.c @@ -204,10 +204,10 @@ group_loads(nir_instr *first, nir_instr *last) if (!can_move(instr, first->pass_flags)) continue; + bool all_uses_after_last = true; nir_def *def = nir_instr_def(instr); - if (def) { - bool all_uses_after_last = true; + if (def) { nir_foreach_use(use, def) { if (nir_src_parent_instr(use)->block == instr->block && nir_src_parent_instr(use)->index <= last->index) { @@ -215,18 +215,20 @@ group_loads(nir_instr *first, nir_instr *last) break; } } + } - if (all_uses_after_last) { - nir_instr *move_instr = instr; - /* Set the last instruction because we'll delete the current one. */ - instr = exec_node_data_forward(nir_instr, instr->node.next, node); + if (all_uses_after_last) { + nir_instr *move_instr = instr; + /* Set the iterator to the next instruction because we'll move + * the current one. + */ + instr = exec_node_data_forward(nir_instr, instr->node.next, node); - /* Move the instruction after the last and update its index - * to indicate that it's after it. - */ - nir_instr_move(nir_after_instr(last), move_instr); - move_instr->index = last->index + 1; - } + /* Move the instruction after the last and update its index to + * indicate that it's after it. + */ + nir_instr_move(nir_after_instr(last), move_instr); + move_instr->index = last->index + 1; } }