From 4c6fdb113f644c75751cae625e684ea487944b2d Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Fri, 8 Nov 2024 17:07:24 +0000 Subject: [PATCH] nir: fix return value of nir_instr_move for some cases This fixes a potential issue where nir_opt_move_discards_to_top would always return progress. Signed-off-by: Rhys Perry Reviewed-by: Alyssa Rosenzweig Reviewed-by: Georg Lehmann Fixes: f97fb1fa55ca ("nir: Add a nir_instr_move helper") Part-of: --- src/compiler/nir/nir.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 12a2a393a58..946cd628ca8 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -1148,10 +1148,24 @@ nir_instr_move(nir_cursor cursor, nir_instr *instr) /* If the cursor happens to refer to this instruction (either before or * after), don't do anything. */ - if ((cursor.option == nir_cursor_before_instr || - cursor.option == nir_cursor_after_instr) && - cursor.instr == instr) - return false; + switch (cursor.option) { + case nir_cursor_before_instr: + if (cursor.instr == instr || nir_instr_prev(cursor.instr) == instr) + return false; + break; + case nir_cursor_after_instr: + if (cursor.instr == instr || nir_instr_next(cursor.instr) == instr) + return false; + break; + case nir_cursor_before_block: + if (cursor.block == instr->block && nir_instr_is_first(instr)) + return false; + break; + case nir_cursor_after_block: + if (cursor.block == instr->block && nir_instr_is_last(instr)) + return false; + break; + } nir_instr_remove(instr); nir_instr_insert(cursor, instr);