------- Comment #3 from rguenth at gcc dot gnu dot org  2010-09-17 15:39 -------
Index: tree-ssa-dom.c
===================================================================
--- tree-ssa-dom.c      (revision 164371)
+++ tree-ssa-dom.c      (working copy)
@@ -1804,6 +1804,37 @@ eliminate_redundant_computations (gimple

   tree def = gimple_get_lhs (stmt);

+  if (gimple_assign_single_p (stmt)
+      && TREE_CODE (def) != SSA_NAME)
+    {
+      tree rhs = gimple_assign_rhs1 (stmt);
+      gimple new_stmt;
+      /* 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, def);
+          SSA_NAME_DEF_STMT (rhs) = defstmt;
+        }
+      else
+        new_stmt = gimple_build_assign (rhs, def);
+      gimple_set_vuse (new_stmt, gimple_vuse (stmt));
+      cached_lhs = lookup_avail_expr (new_stmt, false);
+      if (cached_lhs
+         && (rhs == cached_lhs
+             || (TREE_CODE (rhs) == SSA_NAME
+                 && SSA_NAME_VALUE (rhs) == cached_lhs)))
+       {
+         gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
+         basic_block bb = gimple_bb (stmt);
+         unlink_stmt_vdef (stmt);
+         gsi_remove (&gsi, true);
+         if (gimple_purge_dead_eh_edges (bb))
+           ;
+         return;
+       }
+    }
+
   /* Certain expressions on the RHS can be optimized away, but can not
      themselves be entered into the hash tables.  */
   if (! def


works for both constants and SSA names.  Need to clean the patch up
(removing stmts at that point is probably going to wreck dom, removing
EH edges for sure I guess).


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
           Keywords|missed-optimization         |
   Last reconfirmed|2010-09-17 15:18:08         |2010-09-17 15:39:14
               date|                            |
   Target Milestone|4.3.6                       |---


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45705

Reply via email to