nir/opt_deref: Don't remove casts with alignment information
[mesa.git] / src / compiler / nir / nir_deref.c
index ad0380aa28b026d45d9f2df4789dd80ac9361f57..5b9f97b6620063cdcdc53a24b702a4dcca4b0778 100644 (file)
@@ -924,6 +924,9 @@ opt_replace_struct_wrapper_cast(nir_builder *b, nir_deref_instr *cast)
    if (!parent)
       return false;
 
+   if (cast->cast.align_mul > 0)
+      return false;
+
    if (!glsl_type_is_struct(parent->type))
       return false;
 
@@ -954,6 +957,12 @@ opt_deref_cast(nir_builder *b, nir_deref_instr *cast)
    if (!is_trivial_deref_cast(cast))
       return progress;
 
+   /* If this deref still contains useful alignment information, we don't want
+    * to delete it.
+    */
+   if (cast->cast.align_mul > 0)
+      return progress;
+
    bool trivial_array_cast = is_trivial_array_deref_cast(cast);
 
    assert(cast->dest.is_ssa);