Avoid crashing if instruction is not part of a loop.
authorTorok Edwin <edwintorok@gmail.com>
Mon, 27 Oct 2008 10:18:45 +0000 (10:18 +0000)
committerTorok Edwin <edwintorok@gmail.com>
Mon, 27 Oct 2008 10:18:45 +0000 (10:18 +0000)
If it is not part of a loop it is obviously invariant wrt to all loops.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58240 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/LoopVR.cpp

index 7f5de259caf366d2834799bafd75c6c58f2cb2e9..d0b77b89f0a4e85abe0d49854d6f5a788be97031 100644 (file)
@@ -247,12 +247,13 @@ ConstantRange LoopVR::compute(Value *V) {
     return ConstantRange(cast<IntegerType>(V->getType())->getBitWidth(), false);
 
   LoopInfo &LI = getAnalysis<LoopInfo>();
-  ScalarEvolution &SE = getAnalysis<ScalarEvolution>();
 
   Loop *L = LI.getLoopFor(I->getParent());
-  if (L->isLoopInvariant(I))
+  if (!L || L->isLoopInvariant(I))
     return ConstantRange(cast<IntegerType>(V->getType())->getBitWidth(), false);
 
+  ScalarEvolution &SE = getAnalysis<ScalarEvolution>();
+
   SCEVHandle S = SE.getSCEV(I);
   if (isa<SCEVUnknown>(S) || isa<SCEVCouldNotCompute>(S))
     return ConstantRange(cast<IntegerType>(V->getType())->getBitWidth(), false);