On Tue, 14 Jul 2015, Richard Biener wrote:

> On Mon, 13 Jul 2015, Jeff Law wrote:
> 
> > > 2015-07-13  Richard Biener  <rguent...@suse.de>
> > > 
> > >   * tree-ssa-dom.c (record_temporary_equivalences): Merge
> > >   wideing type conversion case from
> > > record_equivalences_from_incoming_edge
> > >   and use record_equality to record equivalences.
> > >   (record_equivalences_from_incoming_edge): Call
> > >   record_temporary_equivalences.
> > Yea, if testing is clean, that's OK.  Ought to be easier to then add code to
> > handle looking at the uses of X to see if they create an equivalence for the
> > destination of those use statements.
> 
> Applied.  The following patch adds the equivalences for the destination
> of use stmts if they simplify.

Actually I can't use FOR_EACH_IMM_USE_STMT any longer because
record_equivalence ends up calling has_single_use which doens't
handle the special marker FOR_EACH_IMM_USE_STMT inserts.

Thus the following - bootstrapped and tested on x86_64-unknown-linux-gnu.

Ok?

Thanks,
Richard.

2015-07-14  Richard Biener  <rguent...@suse.de>

        * tree-ssa-dom.c (dom_valueize): New function.
        (record_temporary_equivalences): Also record equivalences
        for dominating stmts that have uses of equivalences we are
        about to record.

Index: gcc/tree-ssa-dom.c
===================================================================
--- gcc/tree-ssa-dom.c  (revision 225761)
+++ gcc/tree-ssa-dom.c  (working copy)
@@ -1401,6 +1401,20 @@ simplify_stmt_for_jump_threading (gimple
   return lookup_avail_expr (stmt, false);
 }
 
+/* Valueize hook for gimple_fold_stmt_to_constant_1.  */
+
+static tree
+dom_valueize (tree t)
+{
+  if (TREE_CODE (t) == SSA_NAME)
+    {
+      tree tem = SSA_NAME_VALUE (t);
+      if (tem)
+       return tem;
+    }
+  return t;
+}
+
 /* Record into the equivalence tables any equivalences implied by
    traversing edge E (which are cached in E->aux).
 
@@ -1428,7 +1442,6 @@ record_temporary_equivalences (edge e)
         additional equivalences.  */
       if (lhs
          && TREE_CODE (lhs) == SSA_NAME
-         && is_gimple_constant (rhs)
          && TREE_CODE (rhs) == INTEGER_CST)
        {
          gimple defstmt = SSA_NAME_DEF_STMT (lhs);
@@ -1455,6 +1468,41 @@ record_temporary_equivalences (edge e)
                }
            }
        }
+
+      /* If LHS is an SSA_NAME with a new equivalency then try if
+         stmts with uses of that LHS that dominate the edge destination
+        simplify and allow further equivalences to be recorded.  */
+      if (lhs && TREE_CODE (lhs) == SSA_NAME)
+       {
+         use_operand_p use_p;
+         imm_use_iterator iter;
+         FOR_EACH_IMM_USE_FAST (use_p, iter, lhs)
+           {
+             gimple use_stmt = USE_STMT (use_p);
+
+             /* Only bother to record more equivalences for lhs that
+                can be directly used by e->dest.
+                ???  If the code gets re-organized to a worklist to
+                catch more indirect opportunities and it is made to
+                handle PHIs then this should only consider use_stmts
+                in basic-blocks we have already visited.  */
+             if (e->dest == gimple_bb (use_stmt)
+                 || !dominated_by_p (CDI_DOMINATORS,
+                                     e->dest, gimple_bb (use_stmt)))
+               continue;
+             tree lhs2 = gimple_get_lhs (use_stmt);
+             if (lhs2 && TREE_CODE (lhs2) == SSA_NAME)
+               {
+                 tree res
+                   = gimple_fold_stmt_to_constant_1 (use_stmt, dom_valueize,
+                                                     no_follow_ssa_edges);
+                 if (res
+                     && (TREE_CODE (res) == SSA_NAME
+                         || is_gimple_min_invariant (res)))
+                   record_equality (lhs2, res);
+               }
+           }
+       }
 
       /* If we have 0 = COND or 1 = COND equivalences, record them
         into our expression hash tables.  */

Reply via email to