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 <pendingchaos02@gmail.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Fixes: f97fb1fa55 ("nir: Add a nir_instr_move helper")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32145>
This commit is contained in:
Rhys Perry 2024-11-08 17:07:24 +00:00 committed by Marge Bot
parent 8bbc8284d9
commit 4c6fdb113f

View file

@ -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);