summaryrefslogtreecommitdiff
path: root/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-03-21 21:40:32 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-03-21 21:40:32 +0000
commit1f7bc701b030f5b01553f306cc975eeac1e4d99b (patch)
tree08ee035b780ed67d9e7c4ab3e1f3427b247c45ab /lib/Analysis/ValueTracking.cpp
parentd9ee5c8b285c1adb5a7b6ac532e46048f87346ea (diff)
downloadllvm-1f7bc701b030f5b01553f306cc975eeac1e4d99b.tar.gz
llvm-1f7bc701b030f5b01553f306cc975eeac1e4d99b.tar.bz2
llvm-1f7bc701b030f5b01553f306cc975eeac1e4d99b.tar.xz
Fix INT_MIN gotcha pointed out by Eli Friedman.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128028 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ValueTracking.cpp')
-rw-r--r--lib/Analysis/ValueTracking.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index c36f68c2ae..0f4bfb7b0d 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/lib/Analysis/ValueTracking.cpp
@@ -725,9 +725,10 @@ bool llvm::isPowerOfTwo(Value *V, const TargetData *TD, unsigned Depth) {
isPowerOfTwo(SI->getFalseValue(), TD, Depth);
// An exact divide or right shift can only shift off zero bits, so the result
- // is a power of two only if the first operand is a power of two.
- if (match(V, m_Shr(m_Value(), m_Value())) ||
- match(V, m_IDiv(m_Value(), m_Value()))) {
+ // is a power of two only if the first operand is a power of two and not
+ // copying a sign bit (sdiv int_min, 2).
+ if (match(V, m_LShr(m_Value(), m_Value())) ||
+ match(V, m_UDiv(m_Value(), m_Value()))) {
BinaryOperator *BO = cast<BinaryOperator>(V);
if (BO->isExact())
return isPowerOfTwo(BO->getOperand(0), TD, Depth);