diff --git a/llvm/lib/Transforms/Scalar/LoopFlatten.cpp b/llvm/lib/Transforms/Scalar/LoopFlatten.cpp --- a/llvm/lib/Transforms/Scalar/LoopFlatten.cpp +++ b/llvm/lib/Transforms/Scalar/LoopFlatten.cpp @@ -412,7 +412,7 @@ // increment variable. Increment = dyn_cast(InductionPHI->getIncomingValueForBlock(Latch)); - if (Increment->hasNUsesOrMore(3)) { + if (!Increment || Increment->hasNUsesOrMore(3)) { LLVM_DEBUG(dbgs() << "Could not find valid increment\n"); return false; }