[llvm] [LoopUnroll] Fix out-of-date LoopInfo being used during unroll (PR #191505)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 13:03:20 PDT 2026


================
@@ -1124,21 +1124,26 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
   assert(!UnrollVerifyDomtree ||
          DT->verify(DominatorTree::VerificationLevel::Fast));
 
-  // At this point, the code is well formed.  We now simplify the unrolled loop,
-  // doing constant propagation and dead code elimination as we go.
-  simplifyLoopAfterUnroll(L, !CompletelyUnroll && ULO.Count > 1, LI, SE, DT, AC,
-                          TTI, L->getBlocks(), AA);
-
-  NumCompletelyUnrolled += CompletelyUnroll;
-  ++NumUnrolled;
-
   Loop *OuterL = L->getParentLoop();
+  std::vector<BasicBlock *> Blocks;
   // Update LoopInfo if the loop is completely removed.
   if (CompletelyUnroll) {
+    Blocks = L->getBlocks();
     LI->erase(L);
     // We shouldn't try to use `L` anymore.
     L = nullptr;
-  } else {
+  }
+
+  // At this point, the code is well formed.  We now simplify the unrolled loop,
+  // doing constant propagation and dead code elimination as we go.
+  simplifyLoopAfterUnroll(
+      L, !CompletelyUnroll && ULO.Count > 1, LI, SE, DT, AC, TTI,
----------------
CongzheUalberta wrote:

I think there is still a `LI->replacementPreservesLCSSAForm()` that could be invoked inside `simplifyLoopAfterUnroll()` even if SimplifyIVs is false?

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


More information about the llvm-commits mailing list