Add a m_SignBit pattern for convenience.

llvm-svn: 124656
This commit is contained in:
Duncan Sands 2011-02-01 08:50:33 +00:00
parent cf0ff030a8
commit 4b397fcdc2
2 changed files with 16 additions and 3 deletions

View File

@ -116,6 +116,21 @@ struct all_ones_ty {
/// m_AllOnes() - Match an integer or vector with all bits set to true.
inline all_ones_ty m_AllOnes() { return all_ones_ty(); }
struct signbit_ty {
template<typename ITy>
bool match(ITy *V) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V))
return CI->getValue().isSignBit();
if (const ConstantVector *CV = dyn_cast<ConstantVector>(V))
if (ConstantInt *CI = cast_or_null<ConstantInt>(CV->getSplatValue()))
return CI->getValue().isSignBit();
return false;
}
};
/// m_SignBit() - Match an integer or vector with only the sign bit(s) set.
inline signbit_ty m_SignBit() { return signbit_ty(); }
template<typename Class>
struct bind_ty {

View File

@ -666,9 +666,7 @@ bool llvm::isPowerOfTwo(Value *V, const TargetData *TD, unsigned Depth) {
// (signbit) >>l X is clearly a power of two if the one is not shifted off the
// bottom. If it is shifted off the bottom then the result is undefined.
ConstantInt *CI;
if (match(V, m_LShr(m_ConstantInt(CI), m_Value())) &&
CI->getValue().isSignBit())
if (match(V, m_LShr(m_SignBit(), m_Value())))
return true;
// The remaining tests are all recursive, so bail out if we hit the limit.