Index: lib/Analysis/LoopInfo.cpp =================================================================== --- lib/Analysis/LoopInfo.cpp +++ lib/Analysis/LoopInfo.cpp @@ -223,15 +223,14 @@ BasicBlock *H = getHeader(); for (BasicBlock *BB : this->blocks()) { TerminatorInst *TI = BB->getTerminator(); - MDNode *MD = nullptr; // Check if this terminator branches to the loop header. - for (BasicBlock *Successor : TI->successors()) { - if (Successor == H) { - MD = TI->getMetadata(LLVMContext::MD_loop); - break; - } - } + bool IsPredecessor = any_of(TI->successors(), + [=](BasicBlock *Successor) { return Successor == H; }); + if (!IsPredecessor) + continue; + + MDNode *MD = TI->getMetadata(LLVMContext::MD_loop); if (!MD) return nullptr;