[LoopUnroll] Don't update DT for changeToUnreachable.
authorFlorian Hahn <flo@fhahn.com>
Mon, 16 Jan 2023 12:25:34 +0000 (12:25 +0000)
committerFlorian Hahn <flo@fhahn.com>
Mon, 16 Jan 2023 12:25:34 +0000 (12:25 +0000)
There is no need to update the DT here, because there must be a unique
latch. Hence if the latch is not exiting it must directly branch back
to the original loop header and does not dominate any nodes.

Skipping a DT update here simplifies D141487.

Reviewed By: nikic

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

llvm/lib/Transforms/Utils/LoopUnroll.cpp

index 919a752..cc96d15 100644 (file)
@@ -756,8 +756,13 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
   }
 
   // When completely unrolling, the last latch becomes unreachable.
-  if (!LatchIsExiting && CompletelyUnroll)
-    changeToUnreachable(Latches.back()->getTerminator(), PreserveLCSSA, &DTU);
+  if (!LatchIsExiting && CompletelyUnroll) {
+    // There is no need to update the DT here, because there must be a unique
+    // latch. Hence if the latch is not exiting it must directly branch back to
+    // the original loop header and does not dominate any nodes.
+    assert(LatchBlock->getSingleSuccessor() && "Loop with multiple latches?");
+    changeToUnreachable(Latches.back()->getTerminator(), PreserveLCSSA);
+  }
 
   // Merge adjacent basic blocks, if possible.
   for (BasicBlock *Latch : Latches) {