re PR tree-optimization/35472 (tree DSE is broken)
authorRichard Guenther <rguenther@suse.de>
Wed, 5 Mar 2008 16:13:04 +0000 (16:13 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 5 Mar 2008 16:13:04 +0000 (16:13 +0000)
2008-03-05  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/35472
* tree-ssa-dse.c (dse_optimize_stmt): Do not delete a store
whose single use_stmt has a overlapping set of loaded and
stored symbols as that use_stmt might be a noop assignment then.

* gcc.c-torture/execute/pr35472.c: New testcase.

From-SVN: r132899

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr35472.c [new file with mode: 0644]
gcc/tree-ssa-dse.c

index fe414641c34f31e1c4a60ab31c6f354624d57f5f..a179d15064cc9d289a6ea1a18b00406d1dbf78ae 100644 (file)
@@ -1,3 +1,10 @@
+2008-03-05  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/35472
+       * tree-ssa-dse.c (dse_optimize_stmt): Do not delete a store
+       whose single use_stmt has a overlapping set of loaded and
+       stored symbols as that use_stmt might be a noop assignment then.
+
 2008-03-05  Joel Sherrill <joel.sherrill@oarcorp.com>
 
        * gthr-rtems.h: Implement __gthread_mutex_destroy.
index 8341b280545289de35b3c54e35d805ea2dd93fb8..98246904330bf9daf1237b715e71a9a4a1fff0bb 100644 (file)
@@ -1,3 +1,8 @@
+2008-03-05  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/35472
+       * gcc.c-torture/execute/pr35472.c: New testcase.
+
 2007-03-05  Gabor Loki  <loki@gcc.gnu.org>
 
        PR 33009
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr35472.c b/gcc/testsuite/gcc.c-torture/execute/pr35472.c
new file mode 100644 (file)
index 0000000..c8678e2
--- /dev/null
@@ -0,0 +1,22 @@
+extern void abort (void);
+extern void *memset (void *s, int c, __SIZE_TYPE__ n);
+struct S { int i[16]; };
+struct S *p;
+void __attribute__((noinline))
+foo(struct S *a, struct S *b) { a->i[0] = -1; p = b; }
+void test (void)
+{
+  struct S a, b;
+  memset (&a.i[0], '\0', sizeof (a.i));
+  memset (&b.i[0], '\0', sizeof (b.i));
+  foo (&a, &b);
+  *p = a;
+  *p = b;
+  if (b.i[0] != -1)
+    abort ();
+}
+int main()
+{
+  test();
+  return 0;
+}
index 3e0f04be1245dba638db06918192ea5e7b0f8a4f..f2ec9a505c76bb6a65ee4fc615bfd8bce3d5b33d 100644 (file)
@@ -470,24 +470,23 @@ dse_optimize_stmt (struct dom_walk_data *walk_data,
          vuse_vec_p vv;
          tree stmt_lhs;
 
-         if (LOADED_SYMS (use_stmt))
+         /* If use_stmt is or might be a nop assignment, e.g. for
+            struct { ... } S a, b, *p; ...
+            b = a; b = b;
+            or
+            b = a; b = *p; where p might be &b,
+            or
+            *p = a; *p = b; where p might be &b,
+            or
+            *p = *u; *p = *v; where p might be v, then USE_STMT
+            acts as a use as well as definition, so store in STMT
+            is not dead.  */
+         if (LOADED_SYMS (use_stmt)
+             && bitmap_intersect_p (LOADED_SYMS (use_stmt),
+                                    STORED_SYMS (use_stmt)))
            {
-             tree use_base
-               = get_base_address (GIMPLE_STMT_OPERAND (use_stmt, 0));
-             /* If use_stmt is or might be a nop assignment, e.g. for
-                struct { ... } S a, b, *p; ...
-                b = a; b = b;
-                or
-                b = a; b = *p; where p might be &b, then USE_STMT
-                acts as a use as well as definition, so store in STMT
-                is not dead.  */
-             if (TREE_CODE (use_base) == VAR_DECL
-                 && bitmap_bit_p (LOADED_SYMS (use_stmt),
-                                  DECL_UID (use_base)))
-               {
-                 record_voperand_set (dse_gd->stores, &bd->stores, ann->uid);
-                 return;
-               }
+             record_voperand_set (dse_gd->stores, &bd->stores, ann->uid);
+             return;
            }
 
          if (dump_file && (dump_flags & TDF_DETAILS))