From 656b097b8a07365e8465d224f21d6c6beabd0be9 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 12 Feb 2009 18:08:24 +0000 Subject: Add a utility function to LoopInfo to return the exit block when the loop has exactly one exit, and make use of it in LoopIndexSplit. llvm-svn: 64388 --- llvm/include/llvm/Analysis/LoopInfo.h | 10 ++++++++++ llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp | 9 ++++----- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'llvm') diff --git a/llvm/include/llvm/Analysis/LoopInfo.h b/llvm/include/llvm/Analysis/LoopInfo.h index 0fa4abe0560..b2268a2d74f 100644 --- a/llvm/include/llvm/Analysis/LoopInfo.h +++ b/llvm/include/llvm/Analysis/LoopInfo.h @@ -184,6 +184,16 @@ public: } } + /// getExitingBlock - If getExitingBlocks would return exactly one block, + /// return that block. Otherwise return null. + BlockT *getExitingBlock() const { + SmallVector ExitingBlocks; + getExitingBlocks(ExitingBlocks); + if (ExitingBlocks.size() == 1) + return ExitingBlocks[0]; + return 0; + } + /// getExitBlocks - Return all of the successor blocks of this loop. These /// are the blocks _outside of the current loop_ which are branched to. /// diff --git a/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp b/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp index f625c13d453..2bcb10849ed 100644 --- a/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -236,15 +236,14 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) { } // Reject loop if loop exit condition is not suitable. - SmallVector EBs; - L->getExitingBlocks(EBs); - if (EBs.size() != 1) + BasicBlock *ExitingBlock = L->getExitingBlock(); + if (!ExitingBlock) return false; - BranchInst *EBR = dyn_cast(EBs[0]->getTerminator()); + BranchInst *EBR = dyn_cast(ExitingBlock->getTerminator()); if (!EBR) return false; ExitCondition = dyn_cast(EBR->getCondition()); if (!ExitCondition) return false; - if (EBs[0] != L->getLoopLatch()) return false; + if (ExitingBlock != L->getLoopLatch()) return false; IVExitValue = ExitCondition->getOperand(1); if (!L->isLoopInvariant(IVExitValue)) IVExitValue = ExitCondition->getOperand(0); -- cgit v1.2.3