Remove cycle checking from compute_control_dep_chain

Message ID 20220901130750.DAC2D385829D@sourceware.org
State New, archived
Headers
Series Remove cycle checking from compute_control_dep_chain |

Commit Message

Richard Biener Sept. 1, 2022, 1:07 p.m. UTC
  Now that we have DFS_BACK_EDGE marks we can simply avoid walking
those instead of repeatedly looking for a cycle on the current chain.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	* gimple-predicate-analysis.cc (compute_control_dep_chain):
	Remove cycle detection, instead avoid walking backedges.
---
 gcc/gimple-predicate-analysis.cc | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)
  

Patch

diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc
index 2982268fdfd..a754ff0a029 100644
--- a/gcc/gimple-predicate-analysis.cc
+++ b/gcc/gimple-predicate-analysis.cc
@@ -1035,18 +1035,6 @@  compute_control_dep_chain (basic_block dom_bb, const_basic_block dep_bb,
 	fprintf (dump_file, "chain length exceeds 5: %u\n", cur_chain_len);
     }
 
-  for (unsigned i = 0; i < cur_chain_len; i++)
-    {
-      edge e = cur_cd_chain[i];
-      /* Cycle detected.  */
-      if (e->src == dom_bb)
-	{
-	  if (dump_file)
-	    fprintf (dump_file, "cycle detected\n");
-	  return false;
-	}
-    }
-
   if (DEBUG_PREDICATE_ANALYZER && dump_file)
     fprintf (dump_file,
 	     "%*s%s (dom_bb = %u, dep_bb = %u, cd_chains = { %s }, ...)\n",
@@ -1061,7 +1049,7 @@  compute_control_dep_chain (basic_block dom_bb, const_basic_block dep_bb,
   FOR_EACH_EDGE (e, ei, dom_bb->succs)
     {
       int post_dom_check = 0;
-      if (e->flags & (EDGE_FAKE | EDGE_ABNORMAL))
+      if (e->flags & (EDGE_FAKE | EDGE_ABNORMAL | EDGE_DFS_BACK))
 	continue;
 
       basic_block cd_bb = e->dest;
@@ -1110,6 +1098,12 @@  compute_control_dep_chain (basic_block dom_bb, const_basic_block dep_bb,
 	      break;
 	    }
 
+	  /* The post-dominator walk will reach a backedge only
+	     from a forwarder, otherwise it should choose to exit
+	     the SCC.  */
+	  if (single_succ_p (cd_bb)
+	      && single_succ_edge (cd_bb)->flags & EDGE_DFS_BACK)
+	    break;
 	  cd_bb = get_immediate_dominator (CDI_POST_DOMINATORS, cd_bb);
 	  post_dom_check++;
 	  if (cd_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)