diff options
Diffstat (limited to 'llvm/include/llvm/IR/PatternMatch.h')
| -rw-r--r-- | llvm/include/llvm/IR/PatternMatch.h | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 1a11af27d1a..0f03d7cc56b 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -418,16 +418,42 @@ inline cst_pred_ty<is_lowbit_mask> m_LowBitMask() { return cst_pred_ty<is_lowbit_mask>(); } -struct is_unsigned_less_than { +struct icmp_pred_with_threshold { + ICmpInst::Predicate Pred; const APInt *Thr; - bool isValue(const APInt &C) { return C.ult(*Thr); } -}; -/// Match an integer or vector with every element unsigned less than the -/// Threshold. For vectors, this includes constants with undefined elements. -/// FIXME: is it worth generalizing this to simply take ICmpInst::Predicate? -inline cst_pred_ty<is_unsigned_less_than> -m_SpecificInt_ULT(const APInt &Threshold) { - cst_pred_ty<is_unsigned_less_than> P; + bool isValue(const APInt &C) { + switch (Pred) { + case ICmpInst::Predicate::ICMP_EQ: + return C.eq(*Thr); + case ICmpInst::Predicate::ICMP_NE: + return C.ne(*Thr); + case ICmpInst::Predicate::ICMP_UGT: + return C.ugt(*Thr); + case ICmpInst::Predicate::ICMP_UGE: + return C.uge(*Thr); + case ICmpInst::Predicate::ICMP_ULT: + return C.ult(*Thr); + case ICmpInst::Predicate::ICMP_ULE: + return C.ule(*Thr); + case ICmpInst::Predicate::ICMP_SGT: + return C.sgt(*Thr); + case ICmpInst::Predicate::ICMP_SGE: + return C.sge(*Thr); + case ICmpInst::Predicate::ICMP_SLT: + return C.slt(*Thr); + case ICmpInst::Predicate::ICMP_SLE: + return C.sle(*Thr); + default: + llvm_unreachable("Unhandled ICmp predicate"); + } + } +}; +/// Match an integer or vector with every element comparing 'pred' (eg/ne/...) +/// to Threshold. For vectors, this includes constants with undefined elements. +inline cst_pred_ty<icmp_pred_with_threshold> +m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold) { + cst_pred_ty<icmp_pred_with_threshold> P; + P.Pred = Predicate; P.Thr = &Threshold; return P; } |

