re PR rtl-optimization/84003 (FAIL: g++.dg/torture/pr77745.C with noinline foo)
[gcc.git] / gcc / dse.c
index a0c66aa75ab470824cdf43276d5296ee4824bb10..1ef8f642719f7b16ae517557618e51a6c4fde43c 100644 (file)
--- a/gcc/dse.c
+++ b/gcc/dse.c
@@ -1532,7 +1532,12 @@ record_store (rtx body, bb_info_t bb_info)
              && known_subrange_p (offset, width,
                                   s_info->offset, s_info->width)
              && all_positions_needed_p (s_info, offset - s_info->offset,
-                                        width))
+                                        width)
+             /* We can only remove the later store if the earlier aliases
+                at least all accesses the later one.  */
+             && (MEM_ALIAS_SET (mem) == MEM_ALIAS_SET (s_info->mem)
+                 || alias_set_subset_of (MEM_ALIAS_SET (mem),
+                                         MEM_ALIAS_SET (s_info->mem))))
            {
              if (GET_MODE (mem) == BLKmode)
                {