[llvm] [LV] Fold middle-block branch in post-dissolution removeBranchOnConst. (PR #204243)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 03:10:43 PDT 2026
================
@@ -7789,16 +7818,22 @@ static void connectEpilogueVectorLoop(VPlan &EpiPlan, Loop *L,
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
// Helper to redirect an edge from \p BB to \p VecEpilogueIterationCountCheck
- // to \p NewSucc instead, updating the DomTree.
+ // to \p NewSucc instead, updating the DomTree. No-op if \p BB doesn't branch
+ // there (e.g. its check folded by removeBranchOnConst).
auto RedirectEdge = [&](BasicBlock *BB, BasicBlock *NewSucc) {
+ if (!is_contained(successors(BB), VecEpilogueIterationCountCheck))
+ return;
BB->getTerminator()->replaceUsesOfWith(VecEpilogueIterationCountCheck,
NewSucc);
DTU.applyUpdates(
{{DominatorTree::Delete, BB, VecEpilogueIterationCountCheck},
{DominatorTree::Insert, BB, NewSucc}});
};
- RedirectEdge(EPI.MainLoopIterationCountCheck, VecEpiloguePreHeader);
+ // If the main-loop bypass folded to unconditional, its only successor is
+ // the epilogue check and must be preserved.
+ if (isa<CondBrInst>(EPI.MainLoopIterationCountCheck->getTerminator()))
+ RedirectEdge(EPI.MainLoopIterationCountCheck, VecEpiloguePreHeader);
----------------
artagnon wrote:
If I understand correctly, the main-loop bypass never folded to an unconditional earlier?
https://github.com/llvm/llvm-project/pull/204243
More information about the llvm-commits
mailing list