X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fcompiler%2Fnir%2Fnir_opt_gcm.c;h=879a77a884b046e8b307d97996a46a9f745cfb9c;hb=d8d18516b0aa81f6791889bab7ce14703e65d8b4;hp=77eb8e6da5ab6f0a6983ad0df8e65239dec975d4;hpb=88a2a2e05302179c59e257533ed77d2d0a6a5021;p=mesa.git diff --git a/src/compiler/nir/nir_opt_gcm.c b/src/compiler/nir/nir_opt_gcm.c index 77eb8e6da5a..879a77a884b 100644 --- a/src/compiler/nir/nir_opt_gcm.c +++ b/src/compiler/nir/nir_opt_gcm.c @@ -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) {