Author: Congzhe Cao Date: 2026-05-29T09:57:16-04:00 New Revision: 409361c57949c6a3586a1f8b6015eccf628acfb8
URL: https://github.com/llvm/llvm-project/commit/409361c57949c6a3586a1f8b6015eccf628acfb8 DIFF: https://github.com/llvm/llvm-project/commit/409361c57949c6a3586a1f8b6015eccf628acfb8.diff LOG: Revert "[LoopBoundSplit] Fix edge connections during transformation (#192106)" This reverts commit fa44ca8e5ef6f57c03ba55a4c7b944c9a3ee633e. Added: Modified: llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp Removed: ################################################################################ diff --git a/llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp b/llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp index 27ccce3328d27..a461e1f7fe074 100644 --- a/llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp +++ b/llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp @@ -356,19 +356,6 @@ static bool splitLoopBound(Loop &L, DominatorTree &DT, LoopInfo &LI, BasicBlock *PostLoopPreHeader = PostLoop->getLoopPreheader(); IRBuilder<> Builder(&PostLoopPreHeader->front()); - // Replace exit branch target of pre-loop by post-loop's preheader. - // Note: update the branch here after calling cloneLoopWithPreheader() - // to keep the IR valid. - if (L.getExitBlock() == ExitingCond.BI->getSuccessor(0)) - ExitingCond.BI->setSuccessor(0, PostLoopPreHeader); - else - ExitingCond.BI->setSuccessor(1, PostLoopPreHeader); - - // Update dominator tree. - DT.changeImmediateDominator(PostLoopPreHeader, L.getExitingBlock()); -#ifndef NDEBUG - LI.verify(DT); -#endif // Update phi nodes in header of post-loop. bool isExitingLatch = L.getExitingBlock() == L.getLoopLatch(); Value *ExitingCondLCSSAPhi = nullptr; @@ -390,8 +377,6 @@ static bool splitLoopBound(Loop &L, DominatorTree &DT, LoopInfo &LI, // Find PHI with exiting condition from pre-loop. The PHI should be // SCEVAddRecExpr and have same incoming value from backedge with // ExitingCond. - // - // TODO: Separate SCEV queries from PHI node updates. if (!SE.isSCEVable(PN.getType())) continue; @@ -401,22 +386,13 @@ static bool splitLoopBound(Loop &L, DominatorTree &DT, LoopInfo &LI, ExitingCondLCSSAPhi = LCSSAPhi; } - // Add conditional branch to check we can skip post-loop in its preheader, - // and update DT. + // Add conditional branch to check we can skip post-loop in its preheader. Instruction *OrigBI = PostLoopPreHeader->getTerminator(); ICmpInst::Predicate Pred = ICmpInst::ICMP_NE; Value *Cond = Builder.CreateICmp(Pred, ExitingCondLCSSAPhi, ExitingCond.BoundValue); Builder.CreateCondBr(Cond, PostLoop->getHeader(), PostLoop->getExitBlock()); OrigBI->eraseFromParent(); - DT.changeImmediateDominator(PostLoop->getExitBlock(), PostLoopPreHeader); -#ifdef EXPENSIVE_CHECKS - assert(DT.verify(DominatorTree::VerificationLevel::Full) && - "DT broken during transformation!"); -#else - assert(DT.verify(DominatorTree::VerificationLevel::Fast) && - "DT broken during transformation!"); -#endif // Create new loop bound and add it into preheader of pre-loop. const SCEV *NewBoundSCEV = ExitingCond.BoundSCEV; @@ -443,6 +419,12 @@ static bool splitLoopBound(Loop &L, DominatorTree &DT, LoopInfo &LI, cast<CondBrInst>(VMap[SplitCandidateCond.BI]); ClonedSplitCandidateBI->setCondition(ConstantInt::getFalse(Context)); + // Replace exit branch target of pre-loop by post-loop's preheader. + if (L.getExitBlock() == ExitingCond.BI->getSuccessor(0)) + ExitingCond.BI->setSuccessor(0, PostLoopPreHeader); + else + ExitingCond.BI->setSuccessor(1, PostLoopPreHeader); + // Update phi node in exit block of post-loop. Builder.SetInsertPoint(PostLoopPreHeader, PostLoopPreHeader->begin()); for (PHINode &PN : PostLoop->getExitBlock()->phis()) { @@ -467,6 +449,10 @@ static bool splitLoopBound(Loop &L, DominatorTree &DT, LoopInfo &LI, } } + // Update dominator tree. + DT.changeImmediateDominator(PostLoopPreHeader, L.getExitingBlock()); + DT.changeImmediateDominator(PostLoop->getExitBlock(), PostLoopPreHeader); + // Invalidate cached SE information. SE.forgetLoop(&L); _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
