diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-07-14 19:49:57 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-07-14 19:49:57 +0000 |
commit | 5ea4fc0b33d12c51cc55297747057c00942db662 (patch) | |
tree | 77881cbf6ef9b31a8f4549f98dd2e13162dc7d24 /llvm/lib/Analysis/InstructionSimplify.cpp | |
parent | 6b7f73451f7e83ff3c9e175ab47af444486fd2d7 (diff) | |
download | llvm-5ea4fc0b33d12c51cc55297747057c00942db662.zip llvm-5ea4fc0b33d12c51cc55297747057c00942db662.tar.gz llvm-5ea4fc0b33d12c51cc55297747057c00942db662.tar.bz2 |
InstSimplify: The upper bound of X / C was missing a rounding step
Summary:
When calculating the upper bound of X / -8589934592, we would perform
the following calculation: Floor[INT_MAX / 8589934592]
However, flooring the result would make us wrongly come to the
conclusion that 1073741824 was not in the set of possible values.
Instead, use the ceiling of the result.
Reviewers: nicholas
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D4502
llvm-svn: 212976
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index bd42af1..1054c79 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1964,7 +1964,15 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, APInt Val = CI2->getValue().abs(); if (!Val.isMinValue()) { Lower = IntMin.sdiv(Val); - Upper = IntMax.sdiv(Val) + 1; + APInt Rem; + APInt::sdivrem(IntMax, Val, Upper, Rem); + // We may need to round the result of the INT_MAX / CI2 calculation up + // if we see that the division was not exact. + if (Rem.isMinValue()) + Upper = Upper + 1; + else + Upper = Upper + 2; + assert(Upper != Lower && "Upper part of range has wrapped!"); } } else if (match(LHS, m_LShr(m_Value(), m_ConstantInt(CI2)))) { // 'lshr x, CI2' produces [0, UINT_MAX >> CI2]. |