diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2013-05-18 19:30:37 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2013-05-18 19:30:37 +0000 |
| commit | cb9d4667b7159944598c178dbb6568bc20ae069b (patch) | |
| tree | 8aec7cbe5952aef278045a8fbfb5600103558ce6 /lib/Analysis | |
| parent | 688b5103eb4b70410d1ea54bcd8df4ef2f2ff8e8 (diff) | |
| download | external_llvm-cb9d4667b7159944598c178dbb6568bc20ae069b.zip external_llvm-cb9d4667b7159944598c178dbb6568bc20ae069b.tar.gz external_llvm-cb9d4667b7159944598c178dbb6568bc20ae069b.tar.bz2 | |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182200 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
| -rw-r--r-- | lib/Analysis/ValueTracking.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index 45dcc5e..ca84a0c 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/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). |
