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

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 04:43:11 PDT 2023


================
@@ -368,17 +368,24 @@ 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(getCycle(Pred), getCycle(Succ));
+  if (!Cycle)
+    return;
+
+  // 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);
+
+  CycleT *ParentCycle = Cycle->getParentCycle();
+  while (ParentCycle) {
+    Cycle = ParentCycle;
+    Cycle->appendBlock(NewBlock);
+    ParentCycle = Cycle->getParentCycle();
   }
+
+  BlockMapTopLevel.try_emplace(NewBlock, Cycle);
----------------
petar-avramovic wrote:

OK, so it should add block to cycle and all of the parent cycles and also to innermost and topLevel BlockMap. Are there more details that I am not aware of?

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


More information about the llvm-commits mailing list