re PR middle-end/45705 (Useless store not optimized away)
authorRichard Guenther <rguenther@suse.de>
Mon, 20 Sep 2010 14:40:10 +0000 (14:40 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 20 Sep 2010 14:40:10 +0000 (14:40 +0000)
2010-09-20  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/45705
* tree-ssa-dom.c (optimize_stmt): Perform redundant store elimination.

* gcc.dg/tree-ssa/ssa-dom-dse-1.c: New testcase.

From-SVN: r164434

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-dse-1.c [new file with mode: 0644]
gcc/tree-ssa-dom.c

index 9b35e74..baba93b 100644 (file)
@@ -1,3 +1,8 @@
+2010-09-20  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/45705
+       * tree-ssa-dom.c (optimize_stmt): Perform redundant store elimination.
+
 2010-09-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/45695
index d5340a7..93a35b6 100644 (file)
@@ -1,3 +1,8 @@
+2010-09-20  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/45705
+       * gcc.dg/tree-ssa/ssa-dom-dse-1.c: New testcase.
+
 2010-09-20  Michael Matz  <matz@suse.de>
 
        PR testsuite/45706
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-dse-1.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-dse-1.c
new file mode 100644 (file)
index 0000000..504e4bc
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized" } */
+
+int x;
+void
+foo (void)
+{
+  if (x == 0)
+    x = 0;
+}
+void
+bar (int i)
+{
+  if (x == i)
+    x = i;
+}
+
+/* { dg-final { scan-tree-dump-not "x =" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
index c1abb40..54a35af 100644 (file)
@@ -2178,6 +2178,48 @@ optimize_stmt (basic_block bb, gimple_stmt_iterator si)
       update_stmt_if_modified (stmt);
       eliminate_redundant_computations (&si);
       stmt = gsi_stmt (si);
+
+      /* Perform simple redundant store elimination.  */
+      if (gimple_assign_single_p (stmt)
+         && TREE_CODE (gimple_assign_lhs (stmt)) != SSA_NAME)
+       {
+         tree lhs = gimple_assign_lhs (stmt);
+         tree rhs = gimple_assign_rhs1 (stmt);
+         tree cached_lhs;
+         gimple new_stmt;
+         if (TREE_CODE (rhs) == SSA_NAME)
+           {
+             tree tem = SSA_NAME_VALUE (rhs);
+             if (tem)
+               rhs = tem;
+           }
+         /* Build a new statement with the RHS and LHS exchanged.  */
+         if (TREE_CODE (rhs) == SSA_NAME)
+           {
+             gimple defstmt = SSA_NAME_DEF_STMT (rhs);
+             new_stmt = gimple_build_assign (rhs, lhs);
+             SSA_NAME_DEF_STMT (rhs) = defstmt;
+           }
+         else
+           new_stmt = gimple_build_assign (rhs, lhs);
+         gimple_set_vuse (new_stmt, gimple_vuse (stmt));
+         cached_lhs = lookup_avail_expr (new_stmt, false);
+         if (cached_lhs
+             && rhs == cached_lhs)
+           {
+             basic_block bb = gimple_bb (stmt);
+             int lp_nr = lookup_stmt_eh_lp (stmt);
+             unlink_stmt_vdef (stmt);
+             gsi_remove (&si, true);
+             if (lp_nr != 0)
+               {
+                 bitmap_set_bit (need_eh_cleanup, bb->index);
+                 if (dump_file && (dump_flags & TDF_DETAILS))
+                   fprintf (dump_file, "  Flagged to clear EH edges.\n");
+               }
+             return;
+           }
+       }
     }
 
   /* Record any additional equivalences created by this statement.  */