typedef struct {
nir_shader *shader;
nir_block *start_block;
- struct nir_instr *cursor;
} state;
static void move_instruction_to_start_block(state *state, nir_instr *instr);
static void
move_instruction_to_start_block(state *state, nir_instr *instr)
{
+ /* nothing to do if the instruction is already in the start block */
+ if (instr->block == state->start_block)
+ return;
+
/* first move (recursively) all src's to ensure they appear before
* load*_input that we are trying to move:
*/
/* and then move the instruction itself:
*/
exec_node_remove(&instr->node);
-
- if (state->cursor) {
- exec_node_insert_after(&state->cursor->node, &instr->node);
- } else {
- exec_list_push_head(&state->start_block->instr_list, &instr->node);
- }
-
- state->cursor = instr;
+ exec_list_push_tail(&state->start_block->instr_list, &instr->node);
instr->block = state->start_block;
}
debug_assert(intr->dest.is_ssa);
- state->cursor = NULL;
move_instruction_to_start_block(state, instr);
progress = true;