For PR1336:

Fix a div-by-zero bug noticed by APInt. This fixes:
test/Transforms/IndVarsSimplify/exit_value_tests.llx

llvm-svn: 36099
This commit is contained in:
Reid Spencer 2007-04-16 01:48:37 +00:00
parent 59d3ca99b6
commit 8be22e4e04
1 changed files with 6 additions and 1 deletions

View File

@ -2125,7 +2125,12 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRec) {
// Compute the two solutions for the quadratic formula.
// The divisions must be performed as signed divisions.
APInt NegB(-B);
APInt TwoA(A << 1);
APInt TwoA( A << Two );
if (TwoA == 0) {
const Type* Ty = LC->getValue()->getType();
return std::make_pair(SCEVUnknown::get(UndefValue::get(Ty)),
SCEVUnknown::get(UndefValue::get(Ty)));
}
ConstantInt *Solution1 = ConstantInt::get((NegB + SqrtVal).sdiv(TwoA));
ConstantInt *Solution2 = ConstantInt::get((NegB - SqrtVal).sdiv(TwoA));