Index: lib/Analysis/LoopInfo.cpp =================================================================== --- lib/Analysis/LoopInfo.cpp +++ lib/Analysis/LoopInfo.cpp @@ -360,12 +360,16 @@ } BranchInst *Loop::getLoopGuardBranch() const { - assert(isLoopSimplifyForm() && "Only valid for loop in simplify form"); + if (!isLoopSimplifyForm()) + return nullptr; + BasicBlock *Preheader = getLoopPreheader(); BasicBlock *Latch = getLoopLatch(); - assert(Preheader && Latch && - "Expecting a loop with valid preheader and latch"); - assert(isLoopExiting(Latch) && "Only valid for rotated loop"); + + // Expecting a loop with valid preheader and latch, + // and loop should be in rotate form. + if (!Preheader || !Latch || !isLoopExiting(Latch)) + return nullptr; Instruction *LatchTI = Latch->getTerminator(); if (!LatchTI || LatchTI->getNumSuccessors() != 2)