Index: lib/Transforms/Utils/LoopUnrollRuntime.cpp =================================================================== --- lib/Transforms/Utils/LoopUnrollRuntime.cpp +++ lib/Transforms/Utils/LoopUnrollRuntime.cpp @@ -640,6 +640,13 @@ // iterations. This function adds the appropriate CFG connections. BasicBlock *InsertBot = UseEpilogRemainder ? Exit : PrologExit; BasicBlock *InsertTop = UseEpilogRemainder ? EpilogPreHeader : PrologPreHeader; + // Cloning the loop basic blocks requires that one of the targets of the Latch + // be the (single) exit block out of the loop. This needs to be guaranteed by + // the callers of UnrollRuntimeLoopRemainder. + BranchInst *LatchBR = cast(Latch->getTerminator()); + assert(LatchBR->getSuccessor(0) == Exit || + LatchBR->getSuccessor(1) == Exit && "loop latch successor should be " + "exit block!"); CloneLoopBlocks(L, ModVal, CreateRemainderLoop, UseEpilogRemainder, InsertTop, InsertBot, NewPreHeader, NewBlocks, LoopBlocks, VMap, DT, LI);