[llvm] CycleInfo: Fix splitCriticalEdge (PR #68584)

Sameer Sahasrabuddhe via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 9 21:49:18 PDT 2023


================
@@ -368,16 +368,14 @@ void GenericCycleInfo<ContextT>::splitCriticalEdge(BlockT *Pred, BlockT *Succ,
                                                    BlockT *NewBlock) {
   // Edge Pred-Succ is replaced by edges Pred-NewBlock and NewBlock-Succ, all
   // cycles that had blocks Pred and Succ also get NewBlock.
-  CycleT *Cycle = this->getCycle(Pred);
-  if (Cycle && Cycle->contains(Succ)) {
-    while (Cycle) {
-      // FixMe: Appending NewBlock is fine as a set of blocks in a cycle. When
-      // printing cycle NewBlock is at the end of list but it should be in the
-      // middle to represent actual traversal of a cycle.
-      Cycle->appendBlock(NewBlock);
-      BlockMap.try_emplace(NewBlock, Cycle);
-      Cycle = Cycle->getParentCycle();
-    }
+  CycleT *Cycle = getSmallestCommonCycle(Pred, Succ);
+  while (Cycle) {
+    // FixMe: Appending NewBlock is fine as a set of blocks in a cycle. When
+    // printing cycle NewBlock is at the end of list but it should be in the
+    // middle to represent actual traversal of a cycle.
+    Cycle->appendBlock(NewBlock);
+    BlockMap.try_emplace(NewBlock, Cycle);
----------------
ssahasra wrote:

This can't work, right? The BlockMap should point to the direct parent of NewBlock, but this will keep updating it up the tree.

https://github.com/llvm/llvm-project/pull/68584


More information about the llvm-commits mailing list