[LLVMbugs] [Bug 1215] NEW: can't constantfold sdiv 0, -1

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Wed Feb 21 20:28:28 PST 2007


http://llvm.org/bugs/show_bug.cgi?id=1215

           Summary: can't constantfold sdiv 0, -1
           Product: libraries
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core LLVM classes
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: nicholas at mxc.ca


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.



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



More information about the llvm-bugs mailing list