nir/opt_preamble: Preserve IR when replacing phis
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Fri, 30 Jun 2023 18:21:29 +0000 (14:21 -0400)
committerMarge Bot <emma+marge@anholt.net>
Tue, 10 Oct 2023 13:51:00 +0000 (13:51 +0000)
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24011>

src/compiler/nir/nir_opt_preamble.c

index 2ac0be9..64a5e47 100644 (file)
@@ -592,17 +592,22 @@ nir_opt_preamble(nir_shader *shader, const nir_opt_preamble_options *options,
    nir_builder builder = nir_builder_create(impl);
    b = &builder;
 
+   unsigned max_index = impl->ssa_alloc;
    nir_foreach_block(block, impl) {
       nir_foreach_instr_safe(instr, block) {
          nir_def *def = nir_instr_def(instr);
          if (!def)
             continue;
 
+         /* Ignore new load_preamble instructions */
+         if (def->index >= max_index)
+            continue;
+
          def_state *state = &ctx.states[def->index];
          if (!state->replace)
             continue;
 
-         b->cursor = nir_before_instr(instr);
+         b->cursor = nir_after_instr_and_phis(instr);
 
          nir_def *new_def =
             nir_load_preamble(b, def->num_components, def->bit_size,