[llvm] 90310df - [LoopUnroll] Use changeToUnreachable() (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri May 28 15:11:33 PDT 2021


Author: Nikita Popov
Date: 2021-05-29T00:11:21+02:00
New Revision: 90310dfff8fd17b0cabdee1fd72d675e5eb2aa78

URL: https://github.com/llvm/llvm-project/commit/90310dfff8fd17b0cabdee1fd72d675e5eb2aa78
DIFF: https://github.com/llvm/llvm-project/commit/90310dfff8fd17b0cabdee1fd72d675e5eb2aa78.diff

LOG: [LoopUnroll] Use changeToUnreachable() (NFC)

When fulling unrolling with a non-latch exit, the latch block is
folded to unreachable. Replace this folding with the existing
changeToUnreachable() helper, rather than performing it manually.

This also moves the fold to happen after the manual DT update
for exit blocks. I believe this is correct in that the conversion
of an unconditional backedge into unreachable should not affect
the DT at all.

Differential Revision: https://reviews.llvm.org/D103340

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/LoopUnroll.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
index cb84eb642c96..3574abe81f76 100644
--- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -763,13 +763,6 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
     }
   }
 
-  // When completely unrolling, the last latch becomes unreachable.
-  if (!LatchIsExiting && CompletelyUnroll) {
-    BranchInst *Term = cast<BranchInst>(Latches.back()->getTerminator());
-    new UnreachableInst(Term->getContext(), Term);
-    Term->eraseFromParent();
-  }
-
   // Update dominators of blocks we might reach through exits.
   // Immediate dominator of such block might change, because we add more
   // routes which can lead to the exit: we can now reach it from the copied
@@ -819,6 +812,12 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
          DT->verify(DominatorTree::VerificationLevel::Fast));
 
   DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
+
+  // When completely unrolling, the last latch becomes unreachable.
+  if (!LatchIsExiting && CompletelyUnroll)
+    changeToUnreachable(Latches.back()->getTerminator(), /* UseTrap */ false,
+                        PreserveLCSSA, &DTU);
+
   // Merge adjacent basic blocks, if possible.
   for (BasicBlock *Latch : Latches) {
     BranchInst *Term = dyn_cast<BranchInst>(Latch->getTerminator());


        


More information about the llvm-commits mailing list