re PR tree-optimization/64191 (indirect clobbers messes up dead code elimination...
authorRichard Biener <rguenther@suse.de>
Wed, 10 Dec 2014 09:29:05 +0000 (09:29 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 10 Dec 2014 09:29:05 +0000 (09:29 +0000)
2014-12-10  Richard Biener  <rguenther@suse.de>

PR tree-optimization/64191
* tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Do not
mark clobbers as necessary.
(eliminate_unnecessary_stmts): Keep clobbers live if we can.

* g++.dg/pr64191.C: Make sure we can DCE empty loops with
indirect clobbers.

From-SVN: r218566

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/pr64191.C [new file with mode: 0644]
gcc/tree-ssa-dce.c

index 63008297238b016f3e5f9bb24af2ba62a93a1087..4ceefc83240dcc79006fd8cfab3686c2d582f188 100644 (file)
@@ -1,3 +1,10 @@
+2014-12-10  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/64191
+       * tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Do not
+       mark clobbers as necessary.
+       (eliminate_unnecessary_stmts): Keep clobbers live if we can.
+
 2014-12-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/63594
index 9d03fb8e852798337392ac4efcfe75f8739f66a3..8d18ec974e0719b9dc5bbc1558f461e4e034ff8f 100644 (file)
@@ -1,3 +1,9 @@
+2014-12-10  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/64191
+       * g++.dg/pr64191.C: Make sure we can DCE empty loops with
+       indirect clobbers.
+
 2014-12-09  Alan Lawrence  <alan.lawrence@arm.com>
 
        PR target/63870
diff --git a/gcc/testsuite/g++.dg/pr64191.C b/gcc/testsuite/g++.dg/pr64191.C
new file mode 100644 (file)
index 0000000..e40a62d
--- /dev/null
@@ -0,0 +1,25 @@
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-cddce1" }
+
+struct Bar
+{
+  int i;
+  ~Bar() { }
+};
+void bar_dtor_loop(Bar* p, unsigned int n)
+{
+  if (p) {
+      Bar* e = p + n;
+      while (e > p) {
+         --e;
+         e->~Bar();
+      }
+  }
+}
+
+// The clobber in ~Bar should persist but those inlined into
+// bar_dtor_loop not, nor should the loop therein
+
+// { dg-final { scan-tree-dump-times "CLOBBER" 1 "cddce1" } }
+// { dg-final { scan-tree-dump-times "if" 0 "cddce1" } }
+// { dg-final { cleanup-tree-dump "cddce1" } }
index 1d887c28f866bf67b20926e49af7b18c58661b48..7f68770e40ecfa59f653d941919a935d4e1db0e3 100644 (file)
@@ -292,8 +292,7 @@ mark_stmt_if_obviously_necessary (gimple stmt, bool aggressive)
       break;
 
     case GIMPLE_ASSIGN:
-      if (TREE_CODE (gimple_assign_lhs (stmt)) == SSA_NAME
-         && TREE_CLOBBER_P (gimple_assign_rhs1 (stmt)))
+      if (gimple_clobber_p (stmt))
        return;
       break;
 
@@ -1362,6 +1361,25 @@ eliminate_unnecessary_stmts (void)
          /* If GSI is not necessary then remove it.  */
          if (!gimple_plf (stmt, STMT_NECESSARY))
            {
+             /* Keep clobbers that we can keep live live.  */
+             if (gimple_clobber_p (stmt))
+               {
+                 ssa_op_iter iter;
+                 use_operand_p use_p;
+                 bool dead = false;
+                 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
+                   {
+                     tree name = USE_FROM_PTR (use_p);
+                     if (!SSA_NAME_IS_DEFAULT_DEF (name)
+                         && !bitmap_bit_p (processed, SSA_NAME_VERSION (name)))
+                       {
+                         dead = true;
+                         break;
+                       }
+                   }
+                 if (!dead)
+                   continue;
+               }
              if (!is_gimple_debug (stmt))
                something_changed = true;
              remove_dead_stmt (&gsi, bb);