summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2013-05-18 19:30:37 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2013-05-18 19:30:37 +0000
commitbeab5678a33a333e617079ca851215312446f7b0 (patch)
tree4b464da8dc2a5f2076a42717153be3cdab7ce8cb /llvm/lib/Analysis/ValueTracking.cpp
parent693a1ca6284f5145d261b390156507f12046d4c6 (diff)
downloadbcm5719-llvm-beab5678a33a333e617079ca851215312446f7b0.tar.gz
bcm5719-llvm-beab5678a33a333e617079ca851215312446f7b0.zip
isKnownToBeAPowerOfTwo: (X & Y) + Y is a power of 2 or zero if y is also.
This is useful if something that looks like (x & (1 << y)) ? 64 : 32 is the divisor in a modulo operation. llvm-svn: 182200
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 45dcc5e37ec..ca84a0c5772 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -855,6 +855,17 @@ bool llvm::isKnownToBeAPowerOfTwo(Value *V, bool OrZero, unsigned Depth) {
return false;
}
+ // Adding a power of two to the same power of two is a power of two or zero.
+ if (OrZero && match(V, m_Add(m_Value(X), m_Value(Y)))) {
+ if (match(X, m_And(m_Value(), m_Specific(Y)))) {
+ if (isKnownToBeAPowerOfTwo(Y, /*OrZero*/true, Depth))
+ return true;
+ } else if (match(Y, m_And(m_Value(), m_Specific(X)))) {
+ if (isKnownToBeAPowerOfTwo(X, /*OrZero*/true, Depth))
+ return true;
+ }
+ }
+
// 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 and not
// copying a sign bit (sdiv int_min, 2).
OpenPOWER on IntegriCloud