Index: include/llvm/Analysis/LoopInfoImpl.h =================================================================== --- include/llvm/Analysis/LoopInfoImpl.h +++ include/llvm/Analysis/LoopInfoImpl.h @@ -23,6 +23,10 @@ namespace llvm { +// Max number of loop iterations to check whether a loop is a dedicated +// exit loop. +extern cl::opt MaxDedicateExitIterations; + //===----------------------------------------------------------------------===// // APIs for simple analysis of the loop. See header notes. @@ -87,10 +91,16 @@ // within the loop. SmallVector ExitBlocks; getExitBlocks(ExitBlocks); - for (BlockT *EB : ExitBlocks) - for (BlockT *Predecessor : children>(EB)) + uint64_t Iterations = 0; + for (BlockT *EB : ExitBlocks) { + for (BlockT *Predecessor : children>(EB)) { if (!contains(Predecessor)) return false; + Iterations++; + } + if (Iterations > MaxDedicateExitIterations) + return false; + } // All the requirements are met. return true; } Index: lib/Analysis/LoopInfo.cpp =================================================================== --- lib/Analysis/LoopInfo.cpp +++ lib/Analysis/LoopInfo.cpp @@ -54,6 +54,13 @@ VerifyLoopInfoX("verify-loop-info", cl::location(VerifyLoopInfo), cl::Hidden, cl::desc("Verify loop info (time consuming)")); +namespace llvm { +cl::opt MaxDedicateExitIterations( + "max-dedicate-exit-iterations", cl::Hidden, cl::init(100000), + cl::desc("Max number of loop iterations to check whether a loop is a " + "dedicated exit loop. ")); +} + //===----------------------------------------------------------------------===// // Loop implementation //