new file mode 100644
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dse1-details" } */
+
+enum constraint_expr_type
+{
+ SCALAR, DEREF, ADDRESSOF
+};
+typedef struct constraint_expr
+{
+ enum constraint_expr_type type;
+ unsigned int var;
+ long offset;
+} constraint_expr ;
+typedef struct constraint
+{
+ struct constraint_expr lhs;
+ struct constraint_expr rhs;
+} constraint;
+static _Bool
+constraint_expr_equal (struct constraint_expr x, struct constraint_expr y)
+{
+ return x.type == y.type && x.var == y.var && x.offset == y.offset;
+}
+
+_Bool
+constraint_equal (struct constraint a, struct constraint b)
+{
+ return constraint_expr_equal (a.lhs, b.lhs)
+ && constraint_expr_equal (a.rhs, b.rhs);
+}
+
+/* { dg-final { scan-tree-dump-times "Deleted dead store" 2 "dse1" } } */
+
@@ -439,6 +439,50 @@ dse_possible_dead_store_p (ao_ref *ref, gimple *stmt, gimple **use_stmt)
/* If the statement is a use the store is not dead. */
else if (ref_maybe_used_by_stmt_p (use_stmt, ref))
{
+ /* Handle common cases where we can easily build a ao_ref
+ structure for USE_STMT and in doing so we find that the
+ references hit non-live bytes and thus can be ignored. */
+ if (live_bytes)
+ {
+ if (is_gimple_assign (use_stmt))
+ {
+ /* Other cases were noted as non-aliasing by
+ the call to ref_maybe_used_by_stmt_p. */
+ ao_ref use_ref;
+ ao_ref_init (&use_ref, gimple_assign_rhs1 (use_stmt));
+ if (valid_ao_ref_for_dse (&use_ref)
+ && use_ref.base == ref->base
+ && use_ref.size == use_ref.max_size)
+ {
+ size_t start = use_ref.offset / BITS_PER_UNIT;
+ size_t end = use_ref.size / BITS_PER_UNIT;
+ bitmap z = BITMAP_ALLOC (NULL);
+ bitmap_set_range (z, start, end);
+ bitmap_and_into (z, live_bytes);
+ if (bitmap_empty_p (z))
+ {
+ BITMAP_FREE (z);
+ if (gimple_vdef (use_stmt))
+ {
+ /* If we have already seen a store and
+ this is also a store, then we have to
+ fail. */
+ if (temp)
+ {
+ fail = true;
+ BREAK_FROM_IMM_USE_STMT (ui);
+ }
+
+ /* Otherwise walk through this store. */
+ temp = use_stmt;
+ }
+ continue;
+ }
+ BITMAP_FREE (z);
+ }
+ }
+ }
+
fail = true;
BREAK_FROM_IMM_USE_STMT (ui);
}