https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64853

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Sth like

Index: gcc/tree-ssa-propagate.c
===================================================================
--- gcc/tree-ssa-propagate.c    (revision 220235)
+++ gcc/tree-ssa-propagate.c    (working copy)
@@ -364,6 +364,7 @@ simulate_stmt (gimple stmt)
          FOR_EACH_EDGE (e, ei, bb->succs)
            add_control_edge (e);
        }
+      return;
     }
   else if (val == SSA_PROP_INTERESTING)
     {
@@ -377,6 +378,45 @@ simulate_stmt (gimple stmt)
       if (taken_edge)
        add_control_edge (taken_edge);
     }
+
+  /* If there are no SSA uses on the stmt whose defs are simulated
+     again then this stmt will be never visited again.  */
+  bool has_simulate_again_uses = false;
+  use_operand_p use_p;
+  ssa_op_iter iter;
+  if (gimple_code  (stmt) == GIMPLE_PHI)
+    {
+      edge_iterator ei;
+      edge e;
+      tree arg;
+      FOR_EACH_EDGE (e, ei, gimple_bb (stmt)->preds)
+       if (!(e->flags & EDGE_EXECUTABLE)
+           || ((arg = PHI_ARG_DEF_FROM_EDGE (stmt, e))
+               && TREE_CODE (arg) == SSA_NAME
+               && !SSA_NAME_IS_DEFAULT_DEF (arg)
+               && prop_simulate_again_p (SSA_NAME_DEF_STMT (arg))))
+         {
+           has_simulate_again_uses = true;
+           break;
+         }
+    }
+  else
+    FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
+      {
+       gimple def_stmt = SSA_NAME_DEF_STMT (USE_FROM_PTR (use_p));
+       if (!gimple_nop_p (def_stmt)
+           && prop_simulate_again_p (def_stmt))
+         {
+           has_simulate_again_uses = true;
+           break;
+         }
+      }
+  if (!has_simulate_again_uses)
+    {
+      if (dump_file && (dump_flags & TDF_DETAILS))
+       fprintf (dump_file, "marking stmt to be not simulated again\n");
+      prop_set_simulate_again (stmt, false);
+    }
 }

 /* Process an SSA edge worklist.  WORKLIST is the SSA edge worklist to

for what we discussed on IRC.  Probably makes sense to omit PHI handling
first as that's definitely "interesting".  I'll bootstrap that separately
on the fix for this PR (without handling PHIs).

Reply via email to