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