diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index 55b4b6a74c4..98964eb2357 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -51,10 +51,8 @@ inline leaf_ty m_Value() { return leaf_ty(); } /// m_ConstantInt() - Match an arbitrary ConstantInt and ignore it. inline leaf_ty m_ConstantInt() { return leaf_ty(); } +template struct constantint_ty { - int64_t Val; - explicit constantint_ty(int64_t val) : Val(val) {} - template bool match(ITy *V) { if (const ConstantInt *CI = dyn_cast(V)) { @@ -72,8 +70,9 @@ struct constantint_ty { /// 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 +inline constantint_ty m_ConstantInt() { + return constantint_ty(); } struct zero_ty { @@ -393,12 +392,12 @@ m_Select(const Cond &C, const LHS &L, const RHS &R) { /// m_SelectCst - This matches a select of two constants, e.g.: /// m_SelectCst(m_Value(V), -1, 0) -template -inline SelectClass_match -m_SelectCst(const Cond &C, int64_t L, int64_t R) { - return SelectClass_match(C, m_ConstantInt(L), - m_ConstantInt(R)); +template +inline SelectClass_match, constantint_ty > +m_SelectCst(const Cond &C) { + return SelectClass_match, + constantint_ty >(C, m_ConstantInt(), + m_ConstantInt()); } diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index b1474cca843..83158276e2c 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -4276,18 +4276,18 @@ static Instruction *MatchSelectFromAndOr(Value *A, Value *B, 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 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI, // (x 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) {