[llvm-commits] [llvm] r124656 - in /llvm/trunk: include/llvm/Support/PatternMatch.h lib/Analysis/ValueTracking.cpp
Duncan Sands
baldrick at free.fr
Tue Feb 1 00:50:33 PST 2011
Author: baldrick
Date: Tue Feb 1 02:50:33 2011
New Revision: 124656
URL: http://llvm.org/viewvc/llvm-project?rev=124656&view=rev
Log:
Add a m_SignBit pattern for convenience.
Modified:
llvm/trunk/include/llvm/Support/PatternMatch.h
llvm/trunk/lib/Analysis/ValueTracking.cpp
Modified: llvm/trunk/include/llvm/Support/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PatternMatch.h?rev=124656&r1=124655&r2=124656&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/Support/PatternMatch.h Tue Feb 1 02:50:33 2011
@@ -116,6 +116,21 @@
/// 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 {
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=124656&r1=124655&r2=124656&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Tue Feb 1 02:50:33 2011
@@ -666,9 +666,7 @@
// (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.
More information about the llvm-commits
mailing list