Richi's recent change to fix 88069 is causing various targets to fail
tree-ssa/20030711-2.c.  That test is verifying a variety of
optimizations occur during the first DOM pass.

Prior to Richi's change FRE1 would do some significant cleanups of the
IL and as a result DOM was fully able to optimize the resultant code.

After Richi's change we've got a redundant load in the IL.  After
analyzing the CFG and IL it was clear that DOM *should* be able to
remove the redundant load, but simply wasn't.

DOM would discover that it could statically determine the result of a
branch condition.  This resulted in one arm of the branch becoming
unreachable.  That in turn caused some PHI nodes to become degenerates.

Normally when a PHI node becomes a degenerate we record it as a copy in
the const_and_copies table and *most* of the time we'll propagate the
src value into uses of the dest.  But propagation is not guaranteed
(there's a BZ around that issue you can find if you dig into the history
of some of this code).

Anyway, exposing the degenerate PHI *should* have exposed the redundant
load, but we didn't record anything into the const/copies table for the
virtual phi.  That's a conscious decision to avoid issues with
overlapping lifetimes of virtual SSA_NAMEs.

While investigating the history here I noticed Richi's little trick
which allows propagation of virtuals if we propagate to all the uses.
Twiddling DOM to use that same trick results in the virtual operand
propagating.  That in turn allows DOM to see and remove the redundant load.

Bootstrapped and regression tested on x86_64 where is fixes
20030711-2.c.  Also verified that it fixed various other targets where
that test had started failing.

Installing on the trunk.

jeff
commit 1438e5e18df9f927990074dd32572abf924eba86
Author: Jeff Law <l...@redhat.com>
Date:   Tue Nov 20 18:10:28 2018 -0700

    2018-11-20  Jeff Law  <l...@redhat.com>
    
            PR tree-optimization/88069
            * tree-ssa-dom.c (record_equivalences_from_phis): Propagate away
            degenerate virtual PHIs.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index aece55980f0..5c7a9509b35 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2018-11-20  Jeff Law  <l...@redhat.com>
+
+       PR tree-optimization/88069
+       * tree-ssa-dom.c (record_equivalences_from_phis): Propagate away
+       degenerate virtual PHIs.
+
 2018-11-20  Jakub Jelinek  <ja...@redhat.com>
 
        PR tree-optimization/87895
diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 7787da8b237..ce840488403 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -1106,10 +1106,13 @@ record_equivalences_from_phis (basic_block bb)
 {
   gphi_iterator gsi;
 
-  for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+  for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); )
     {
       gphi *phi = gsi.phi ();
 
+      /* We might eliminate the PHI, so advance GSI now.  */
+      gsi_next (&gsi);
+
       tree lhs = gimple_phi_result (phi);
       tree rhs = NULL;
       size_t i;
@@ -1159,9 +1162,26 @@ record_equivalences_from_phis (basic_block bb)
         this, since this is a true assignment and not an equivalence
         inferred from a comparison.  All uses of this ssa name are dominated
         by this assignment, so unwinding just costs time and space.  */
-      if (i == gimple_phi_num_args (phi)
-         && may_propagate_copy (lhs, rhs))
-       set_ssa_name_value (lhs, rhs);
+      if (i == gimple_phi_num_args (phi))
+       {
+         if (may_propagate_copy (lhs, rhs))
+           set_ssa_name_value (lhs, rhs);
+         else if (virtual_operand_p (lhs))
+           {
+             gimple *use_stmt;
+             imm_use_iterator iter;
+             use_operand_p use_p;
+             /* For virtual operands we have to propagate into all uses as
+                otherwise we will create overlapping life-ranges.  */
+             FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
+               FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
+                 SET_USE (use_p, rhs);
+             if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
+               SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs) = 1;
+             gimple_stmt_iterator tmp_gsi = gsi_for_stmt (phi);
+             remove_phi_node (&tmp_gsi, true);
+           }
+       }
     }
 }
 

Reply via email to