From e54a20e094242799d55be50ac880321f7855851e Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Mon, 12 Feb 2018 11:10:58 +0000 Subject: [PATCH] [LoopInterchange] Simplify splitInnerLoopHeader logic (NFC). We can use SplitBlock for both cases, which makes the code slightly simpler and updates both LoopInfo and the dominator tree. llvm-svn: 324881 --- llvm/lib/Transforms/Scalar/LoopInterchange.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp index 4f8dafe..8540f5a 100644 --- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp +++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp @@ -1222,17 +1222,12 @@ void LoopInterchangeTransform::splitInnerLoopHeader() { // stay in the innerloop body. BasicBlock *InnerLoopHeader = InnerLoop->getHeader(); BasicBlock *InnerLoopPreHeader = InnerLoop->getLoopPreheader(); + SplitBlock(InnerLoopHeader, InnerLoopHeader->getFirstNonPHI(), DT, LI); if (InnerLoopHasReduction) { - // Note: The induction PHI must be the first PHI for this to work - BasicBlock *New = InnerLoopHeader->splitBasicBlock( - ++(InnerLoopHeader->begin()), InnerLoopHeader->getName() + ".split"); - if (LI) - if (Loop *L = LI->getLoopFor(InnerLoopHeader)) - L->addBasicBlockToLoop(New, *LI); - - // Adjust Reduction PHI's in the block. + // Adjust Reduction PHI's in the block. The induction PHI must be the first + // PHI in InnerLoopHeader for this to work. SmallVector PHIVec; - for (auto I = New->begin(); isa(I); ++I) { + for (auto I = std::next(InnerLoopHeader->begin()); isa(I); ++I) { PHINode *PHI = dyn_cast(I); Value *V = PHI->getIncomingValueForBlock(InnerLoopPreHeader); PHI->replaceAllUsesWith(V); @@ -1241,8 +1236,6 @@ void LoopInterchangeTransform::splitInnerLoopHeader() { for (PHINode *P : PHIVec) { P->eraseFromParent(); } - } else { - SplitBlock(InnerLoopHeader, InnerLoopHeader->getFirstNonPHI(), DT, LI); } DEBUG(dbgs() << "Output of splitInnerLoopHeader InnerLoopHeaderSucc & " -- 2.7.4