[llvm] a654971 - [LoopUnroll] Don't update DT for changeToUnreachable.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 16 04:25:58 PST 2023


Author: Florian Hahn
Date: 2023-01-16T12:25:34Z
New Revision: a6549718d9ba2fdcd14fb8651aeb5000840fa337

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

LOG: [LoopUnroll] Don't update DT for changeToUnreachable.

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

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 919a75219d4d5..cc96d15d5e596 100644
--- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -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) {


        


More information about the llvm-commits mailing list