diff --git a/llvm/lib/Transforms/Scalar/LoopUnroll.cpp b/llvm/lib/Transforms/Scalar/LoopUnroll.cpp index 3ffdfac33b60..676afb0e226f 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnroll.cpp @@ -269,7 +269,8 @@ bool LoopUnroll::visitLoop(Loop *L) { if (isa(InVal)) InVal = LastValueMap[InVal]; (*SI)->removeIncomingValue(LatchBlock, false); - (*SI)->addIncoming(InVal, cast(LastValueMap[LatchBlock])); + if (InVal) + (*SI)->addIncoming(InVal, cast(LastValueMap[LatchBlock])); } }