An instruction's operands aren't necessarily instructions or constants. They
authorNick Lewycky <nicholas@mxc.ca>
Fri, 14 Oct 2011 09:38:46 +0000 (09:38 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Fri, 14 Oct 2011 09:38:46 +0000 (09:38 +0000)
could be arguments, for example.

No testcase because this is a bug-fix broken out of a larger optimization patch.

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

lib/Analysis/ScalarEvolution.cpp

index f09f357c61cd8bbb0f30f622f88f97e2f3b02dcd..e0ac56c65e76b66b4c5392a175ccc1fd4bb0efb3 100644 (file)
@@ -4764,7 +4764,8 @@ static Constant *EvaluateExpression(Value *V, const Loop *L,
   for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
     Instruction *Operand = dyn_cast<Instruction>(I->getOperand(i));
     if (!Operand) {
-      Operands[i] = cast<Constant>(I->getOperand(i));
+      Operands[i] = dyn_cast<Constant>(I->getOperand(i));
+      if (!Operands[i]) return 0;
       continue;
     }
     Constant *C = EvaluateExpression(Operand, L, Vals, TD);