[PATCH] D126386: [ModuloSchedule] Fix terminator update when peeling.

Hendrik Greving via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 25 08:22:12 PDT 2022


hgreving created this revision.
hgreving added reviewers: ThomasRaoux, jmolloy.
Herald added a subscriber: hiraditya.
Herald added a project: All.
hgreving requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Fixes a bug of us not correctly updating the terminator of the loop's
preheader, if multiple terminating branch instructions are present.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126386

Files:
  llvm/lib/CodeGen/MachineLoopUtils.cpp


Index: llvm/lib/CodeGen/MachineLoopUtils.cpp
===================================================================
--- llvm/lib/CodeGen/MachineLoopUtils.cpp
+++ llvm/lib/CodeGen/MachineLoopUtils.cpp
@@ -103,10 +103,14 @@
 
   DebugLoc DL;
   if (Direction == LPD_Front) {
-    Preheader->replaceSuccessor(Loop, NewBB);
+    Preheader->ReplaceUsesOfBlockWith(Loop, NewBB);
     NewBB->addSuccessor(Loop);
     Loop->replacePhiUsesWith(Preheader, NewBB);
-    if (TII->removeBranch(*Preheader) > 0)
+    Preheader->updateTerminator(Loop);
+    if (Preheader->getFallThrough() == NewBB)
+      // Technically we don't need this, but some code downstream, specifically
+      // the peeling modulo expander is always expecting a terminator in the
+      // prologs.
       TII->insertBranch(*Preheader, NewBB, nullptr, {}, DL);
     TII->removeBranch(*NewBB);
     TII->insertBranch(*NewBB, Loop, nullptr, {}, DL);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126386.432009.patch
Type: text/x-patch
Size: 909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220525/a93c9a6c/attachment.bin>


More information about the llvm-commits mailing list