I encountered an assertion failure in scalar evolutions: opt: ScalarEvolution.cpp:2362: llvm::SCEVHandle llvm::SCEVAddRecExpr::getNumIterationsInRange(llvm::ConstantRange, bool) const: Assertion `isa<ConstantInt>(ExitValue) && "Constant folding of integers not implemented?"' failed. The assertion has found a real problem. The line in question is "ConstantExpr::getSDiv(ExitValue, A);" where ExitValue is i32 0 and A is i32 -1. getSDiv eventually gets into this case in ConstantFoldBinaryInstruction (ConstantFolding.cpp): 00572 case Instruction::SDiv: 00573 if (CI2->isNullValue()) return 0; // X / 0 -> can't fold 00574 if (CI2->isAllOnesValue() && 00575 (((CI1->getType()->getPrimitiveSizeInBits() == 64) && 00576 (CI1->getSExtValue() == INT64_MIN)) || 00577 (CI1->getSExtValue() == -CI1->getSExtValue()))) 00578 return 0; // MIN_INT / -1 -> overflow 00579 return ConstantInt::get(C1->getType(), 00580 CI1->getSExtValue() / CI2->getSExtValue()); Given that CI1 is the left hand side, CI1->getSExtValue() == -CI1->getSExtValue() when the left is 0. This code also fails to properly fold arbitrary precision integers, so it deserves to be rewritten.
Created attachment 680 [details] llvm-as pr1215.ll | opt -indvars
Fixed, testcase here: Transforms/ConstProp/2007-02-23-sdiv.ll Patch here: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070219/044968.html -Chris
patch actually here: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of- Mon-20070219/044969.html