nir: fix nir_lower_wpos_ytransform when gl_FragCoord is a system value
[mesa.git] / src / compiler / nir / nir_opt_gcm.c
index 77eb8e6da5ab6f0a6983ad0df8e65239dec975d4..879a77a884b046e8b307d97996a46a9f745cfb9c 100644 (file)
@@ -320,18 +320,19 @@ gcm_schedule_late_def(nir_ssa_def *def, void *void_state)
    if (lca == NULL)
       return true;
 
-   /* We know have the LCA of all of the uses.  If our invariants hold,
+   /* We now have the LCA of all of the uses.  If our invariants hold,
     * this is dominated by the block that we chose when scheduling early.
     * We now walk up the dominance tree and pick the lowest block that is
     * as far outside loops as we can get.
     */
    nir_block *best = lca;
-   while (lca != def->parent_instr->block) {
-      assert(lca);
-      if (state->blocks[lca->index].loop_depth <
+   for (nir_block *block = lca; block != NULL; block = block->imm_dom) {
+      if (state->blocks[block->index].loop_depth <
           state->blocks[best->index].loop_depth)
-         best = lca;
-      lca = lca->imm_dom;
+         best = block;
+
+      if (block == def->parent_instr->block)
+         break;
    }
    def->parent_instr->block = best;
 
@@ -455,6 +456,9 @@ gcm_place_instr(nir_instr *instr, struct gcm_state *state)
 static bool
 opt_gcm_impl(nir_function_impl *impl, bool value_number)
 {
+   nir_metadata_require(impl, nir_metadata_block_index |
+                              nir_metadata_dominance);
+
    struct gcm_state state;
 
    state.impl = impl;
@@ -462,9 +466,6 @@ opt_gcm_impl(nir_function_impl *impl, bool value_number)
    exec_list_make_empty(&state.instrs);
    state.blocks = rzalloc_array(NULL, struct gcm_block_info, impl->num_blocks);
 
-   nir_metadata_require(impl, nir_metadata_block_index |
-                              nir_metadata_dominance);
-
    gcm_build_block_info(&impl->body, &state, 0);
 
    nir_foreach_block(block, impl) {