nir: fix memory leak in nir_cf_list_clone
[mesa.git] / src / compiler / nir / nir_deref.c
index 83c401282c551cf01f79c99d2259970c9d9bad91..4191b7b75992102cd0b25b978b8edf12da5c53c2 100644 (file)
@@ -279,8 +279,6 @@ nir_deref_instr_get_const_offset(nir_deref_instr *deref,
    nir_deref_path path;
    nir_deref_path_init(&path, deref, NULL);
 
-   assert(path.path[0]->deref_type == nir_deref_type_var);
-
    unsigned offset = 0;
    for (nir_deref_instr **p = &path.path[1]; *p; p++) {
       switch ((*p)->deref_type) {
@@ -295,6 +293,9 @@ nir_deref_instr_get_const_offset(nir_deref_instr *deref,
                                                 (*p)->strct.index);
         break;
       }
+      case nir_deref_type_cast:
+         /* A cast doesn't contribute to the offset */
+         break;
       default:
          unreachable("Unsupported deref type");
       }
@@ -312,8 +313,6 @@ nir_build_deref_offset(nir_builder *b, nir_deref_instr *deref,
    nir_deref_path path;
    nir_deref_path_init(&path, deref, NULL);
 
-   assert(path.path[0]->deref_type == nir_deref_type_var);
-
    nir_ssa_def *offset = nir_imm_intN_t(b, 0, deref->dest.ssa.bit_size);
    for (nir_deref_instr **p = &path.path[1]; *p; p++) {
       switch ((*p)->deref_type) {
@@ -332,6 +331,9 @@ nir_build_deref_offset(nir_builder *b, nir_deref_instr *deref,
          offset = nir_iadd_imm(b, offset, field_offset);
          break;
       }
+      case nir_deref_type_cast:
+         /* A cast doesn't contribute to the offset */
+         break;
       default:
          unreachable("Unsupported deref type");
       }
@@ -514,8 +516,8 @@ nir_compare_deref_paths(nir_deref_path *a_path,
    }
 
    /* We're at either the tail or the divergence point between the two deref
-    * paths.  Look to see if either contains a ptr_as_array deref.  It it
-    * does we don't know how to safely make any inferences.  Hopefully,
+    * paths.  Look to see if either contains cast or a ptr_as_array deref.  If
+    * it does we don't know how to safely make any inferences.  Hopefully,
     * nir_opt_deref will clean most of these up and we can start inferring
     * things again.
     *
@@ -525,11 +527,13 @@ nir_compare_deref_paths(nir_deref_path *a_path,
     * different constant indices.
     */
    for (nir_deref_instr **t_p = a_p; *t_p; t_p++) {
-      if ((*t_p)->deref_type == nir_deref_type_ptr_as_array)
+      if ((*t_p)->deref_type == nir_deref_type_cast ||
+          (*t_p)->deref_type == nir_deref_type_ptr_as_array)
          return nir_derefs_may_alias_bit;
    }
    for (nir_deref_instr **t_p = b_p; *t_p; t_p++) {
-      if ((*t_p)->deref_type == nir_deref_type_ptr_as_array)
+      if ((*t_p)->deref_type == nir_deref_type_cast ||
+          (*t_p)->deref_type == nir_deref_type_ptr_as_array)
          return nir_derefs_may_alias_bit;
    }
 
@@ -731,7 +735,7 @@ nir_rematerialize_derefs_in_use_blocks_impl(nir_function_impl *impl)
    struct rematerialize_deref_state state = { 0 };
    nir_builder_init(&state.builder, impl);
 
-   nir_foreach_block(block, impl) {
+   nir_foreach_block_unstructured(block, impl) {
       state.block = block;
 
       /* Start each block with a fresh cache */