diff options
author | Craig Topper <craig.topper@intel.com> | 2017-07-07 19:56:20 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2017-07-07 19:56:20 +0000 |
commit | 2c4018064e55ae16ae515e07d163063eda92fa62 (patch) | |
tree | aa0f38e8ceb84bb5f75ba827845d804030312ef9 | |
parent | 45f53414ad273da35b1182e6de9b694a7ff52cf0 (diff) | |
download | bcm5719-llvm-2c4018064e55ae16ae515e07d163063eda92fa62.tar.gz bcm5719-llvm-2c4018064e55ae16ae515e07d163063eda92fa62.zip |
[PatternMatch] Implement m_One and m_AllOnes using Constant::isOneValue/isAllOnesValue instead of doing our own splat detection and checking the resulting APInt.
Should result in less compiled code.
llvm-svn: 307431
-rw-r--r-- | llvm/include/llvm/IR/PatternMatch.h | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 5b69e7855cc..3d15f9d0bb0 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -176,6 +176,28 @@ struct match_nan { /// Match an arbitrary NaN constant. This includes quiet and signalling nans. inline match_nan m_NaN() { return match_nan(); } +struct match_one { + template <typename ITy> bool match(ITy *V) { + if (const auto *C = dyn_cast<Constant>(V)) + return C->isOneValue(); + return false; + } +}; + +/// \brief Match an integer 1 or a vector with all elements equal to 1. +inline match_one m_One() { return match_one(); } + +struct match_all_ones { + template <typename ITy> bool match(ITy *V) { + if (const auto *C = dyn_cast<Constant>(V)) + return C->isAllOnesValue(); + return false; + } +}; + +/// \brief Match an integer 1 or a vector with all elements equal to 1. +inline match_all_ones m_AllOnes() { return match_all_ones(); } + struct apint_match { const APInt *&Res; @@ -259,24 +281,6 @@ template <typename Predicate> struct api_pred_ty : public Predicate { } }; -struct is_one { - bool isValue(const APInt &C) { return C.isOneValue(); } -}; - -/// \brief Match an integer 1 or a vector with all elements equal to 1. -inline cst_pred_ty<is_one> m_One() { return cst_pred_ty<is_one>(); } -inline api_pred_ty<is_one> m_One(const APInt *&V) { return V; } - -struct is_all_ones { - bool isValue(const APInt &C) { return C.isAllOnesValue(); } -}; - -/// \brief Match an integer or vector with all bits set to true. -inline cst_pred_ty<is_all_ones> m_AllOnes() { - return cst_pred_ty<is_all_ones>(); -} -inline api_pred_ty<is_all_ones> m_AllOnes(const APInt *&V) { return V; } - struct is_sign_mask { bool isValue(const APInt &C) { return C.isSignMask(); } }; |