aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2011-10-28 18:30:05 +0000
committerDuncan Sands <baldrick@free.fr>2011-10-28 18:30:05 +0000
commit4604fc7791314af7ba7b66999e4c7fb75a4d9f6e (patch)
tree3e33c7f131400070536fc37376e488bdb946ee02 /lib/Analysis/ValueTracking.cpp
parentc65c747bc4ee7d3ca8463d33708bbb2aed38a809 (diff)
A shift of a power of two is a power of two or zero.
For completeness - not spotted in the wild. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143211 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ValueTracking.cpp')
-rw-r--r--lib/Analysis/ValueTracking.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index 90757f9798..9f7b5b501a 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/lib/Analysis/ValueTracking.cpp
@@ -769,6 +769,12 @@ bool llvm::isPowerOfTwo(Value *V, const TargetData *TD, bool OrZero,
if (Depth++ == MaxDepth)
return false;
+ Value *X = 0, *Y = 0;
+ // A shift of a power of two is a power of two or zero.
+ if (OrZero && (match(V, m_Shl(m_Value(X), m_Value())) ||
+ match(V, m_Shr(m_Value(X), m_Value()))))
+ return isPowerOfTwo(X, TD, /*OrZero*/true, Depth);
+
if (ZExtInst *ZI = dyn_cast<ZExtInst>(V))
return isPowerOfTwo(ZI->getOperand(0), TD, OrZero, Depth);
@@ -776,7 +782,6 @@ bool llvm::isPowerOfTwo(Value *V, const TargetData *TD, bool OrZero,
return isPowerOfTwo(SI->getTrueValue(), TD, OrZero, Depth) &&
isPowerOfTwo(SI->getFalseValue(), TD, OrZero, Depth);
- Value *X = 0, *Y = 0;
if (OrZero && match(V, m_And(m_Value(X), m_Value(Y)))) {
// A power of two and'd with anything is a power of two or zero.
if (isPowerOfTwo(X, TD, /*OrZero*/true, Depth) ||