can't constantfold sdiv 0, -1 #1587
Labels
bugzilla
Issues migrated from bugzilla
compile-fail
Use [accepts-invalid] and [rejects-valid] instead
llvm:core
Extended Description
I encountered an assertion failure in scalar evolutions:
opt: ScalarEvolution.cpp:2362: llvm::SCEVHandle
llvm::SCEVAddRecExpr::getNumIterationsInRange(llvm::ConstantRange, bool) const:
Assertion `isa(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.
The text was updated successfully, but these errors were encountered: