Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't constantfold sdiv 0, -1 #1587

Closed
nlewycky opened this issue Feb 22, 2007 · 3 comments
Closed

can't constantfold sdiv 0, -1 #1587

nlewycky opened this issue Feb 22, 2007 · 3 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla compile-fail Use [accepts-invalid] and [rejects-valid] instead llvm:core

Comments

@nlewycky
Copy link
Contributor

Bugzilla Link 1215
Resolution FIXED
Resolved on Feb 22, 2010 12:40
Version trunk
OS All
Attachments [llvm-as pr1215.ll

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.

@nlewycky
Copy link
Contributor Author

assigned to @lattner

@lattner
Copy link
Collaborator

lattner commented Feb 24, 2007

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

@lattner
Copy link
Collaborator

lattner commented Feb 24, 2007

patch actually here: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-
Mon-20070219/044969.html

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla compile-fail Use [accepts-invalid] and [rejects-valid] instead llvm:core
Projects
None yet
Development

No branches or pull requests

2 participants