[llvm-commits] [llvm] r61776 - in /llvm/trunk: include/llvm/Support/PatternMatch.h lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
sabre at nondot.org
Mon Jan 5 15:53:12 PST 2009
Author: lattner
Date: Mon Jan 5 17:53:12 2009
New Revision: 61776
URL: http://llvm.org/viewvc/llvm-project?rev=61776&view=rev
Log:
Change m_ConstantInt and m_SelectCst to take their constant integers
as template arguments instead of as instance variables, exposing more
optimization opportunities to the compiler earlier.
Modified:
llvm/trunk/include/llvm/Support/PatternMatch.h
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Modified: llvm/trunk/include/llvm/Support/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PatternMatch.h?rev=61776&r1=61775&r2=61776&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/Support/PatternMatch.h Mon Jan 5 17:53:12 2009
@@ -51,10 +51,8 @@
/// m_ConstantInt() - Match an arbitrary ConstantInt and ignore it.
inline leaf_ty<ConstantInt> m_ConstantInt() { return leaf_ty<ConstantInt>(); }
+template<int64_t Val>
struct constantint_ty {
- int64_t Val;
- explicit constantint_ty(int64_t val) : Val(val) {}
-
template<typename ITy>
bool match(ITy *V) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
@@ -72,8 +70,9 @@
/// m_ConstantInt(int64_t) - Match a ConstantInt with a specific value
/// and ignore it.
-inline constantint_ty m_ConstantInt(int64_t Val) {
- return constantint_ty(Val);
+template<int64_t Val>
+inline constantint_ty<Val> m_ConstantInt() {
+ return constantint_ty<Val>();
}
struct zero_ty {
@@ -393,12 +392,12 @@
/// m_SelectCst - This matches a select of two constants, e.g.:
/// m_SelectCst(m_Value(V), -1, 0)
-template<typename Cond>
-inline SelectClass_match<Cond, constantint_ty, constantint_ty>
-m_SelectCst(const Cond &C, int64_t L, int64_t R) {
- return SelectClass_match<Cond, constantint_ty,
- constantint_ty>(C, m_ConstantInt(L),
- m_ConstantInt(R));
+template<int64_t L, int64_t R, typename Cond>
+inline SelectClass_match<Cond, constantint_ty<L>, constantint_ty<R> >
+m_SelectCst(const Cond &C) {
+ return SelectClass_match<Cond, constantint_ty<L>,
+ constantint_ty<R> >(C, m_ConstantInt<L>(),
+ m_ConstantInt<R>());
}
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=61776&r1=61775&r2=61776&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Mon Jan 5 17:53:12 2009
@@ -4276,18 +4276,18 @@
Value *C, Value *D) {
// If A is not a select of -1/0, this cannot match.
Value *Cond = 0;
- if (!match(A, m_SelectCst(m_Value(Cond), -1, 0)))
+ if (!match(A, m_SelectCst<-1, 0>(m_Value(Cond))))
return 0;
// ((cond?-1:0)&C) | (B&(cond?0:-1)) -> cond ? C : B.
- if (match(D, m_SelectCst(m_Specific(Cond), 0, -1)))
+ if (match(D, m_SelectCst<0, -1>(m_Specific(Cond))))
return SelectInst::Create(Cond, C, B);
- if (match(D, m_Not(m_SelectCst(m_Specific(Cond), -1, 0))))
+ if (match(D, m_Not(m_SelectCst<-1, 0>(m_Specific(Cond)))))
return SelectInst::Create(Cond, C, B);
// ((cond?-1:0)&C) | ((cond?0:-1)&D) -> cond ? C : D.
- if (match(B, m_SelectCst(m_Specific(Cond), 0, -1)))
+ if (match(B, m_SelectCst<0, -1>(m_Specific(Cond))))
return SelectInst::Create(Cond, C, D);
- if (match(B, m_Not(m_SelectCst(m_Specific(Cond), -1, 0))))
+ if (match(B, m_Not(m_SelectCst<-1, 0>(m_Specific(Cond)))))
return SelectInst::Create(Cond, C, D);
return 0;
}
@@ -8713,11 +8713,11 @@
// (x <s 0) ? -1 : 0 -> ashr x, 31 -> all ones if signed
// (x >s -1) ? -1 : 0 -> ashr x, 31 -> all ones if not signed
CmpInst::Predicate Pred = CmpInst::BAD_ICMP_PREDICATE;
- if (match(TrueVal, m_ConstantInt(-1)) &&
- match(FalseVal, m_ConstantInt(0)))
+ if (match(TrueVal, m_ConstantInt<-1>()) &&
+ match(FalseVal, m_ConstantInt<0>()))
Pred = ICI->getPredicate();
- else if (match(TrueVal, m_ConstantInt(0)) &&
- match(FalseVal, m_ConstantInt(-1)))
+ else if (match(TrueVal, m_ConstantInt<0>()) &&
+ match(FalseVal, m_ConstantInt<-1>()))
Pred = CmpInst::getInversePredicate(ICI->getPredicate());
if (Pred != CmpInst::BAD_ICMP_PREDICATE) {
More information about the llvm-commits
mailing list