diff --git a/llvm/lib/Analysis/LoopVR.cpp b/llvm/lib/Analysis/LoopVR.cpp index 7f5de259caf3..d0b77b89f0a4 100644 --- a/llvm/lib/Analysis/LoopVR.cpp +++ b/llvm/lib/Analysis/LoopVR.cpp @@ -247,12 +247,13 @@ ConstantRange LoopVR::compute(Value *V) { return ConstantRange(cast(V->getType())->getBitWidth(), false); LoopInfo &LI = getAnalysis(); - ScalarEvolution &SE = getAnalysis(); Loop *L = LI.getLoopFor(I->getParent()); - if (L->isLoopInvariant(I)) + if (!L || L->isLoopInvariant(I)) return ConstantRange(cast(V->getType())->getBitWidth(), false); + ScalarEvolution &SE = getAnalysis(); + SCEVHandle S = SE.getSCEV(I); if (isa(S) || isa(S)) return ConstantRange(cast(V->getType())->getBitWidth(), false);