diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2019-07-22 22:09:24 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2019-07-22 22:09:24 +0000 |
commit | 3a94765bfca288c5f824f9a6d216f2129dfcd7ee (patch) | |
tree | f49dd8c532cca1e2afe0f5137ae472a4dd99c6d3 | |
parent | 068942728058d6e52f95276cfaf6e0d73099110a (diff) | |
download | bcm5719-llvm-3a94765bfca288c5f824f9a6d216f2129dfcd7ee.tar.gz bcm5719-llvm-3a94765bfca288c5f824f9a6d216f2129dfcd7ee.zip |
[NFC][PatternMatch] Refactor code into a proper "matcher for any integral constant"
Having it as a proper matcher is better for reusability elsewhere
(in a follow-up patch.)
llvm-svn: 366752
-rw-r--r-- | llvm/include/llvm/IR/PatternMatch.h | 9 | ||||
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineInternal.h | 19 |
2 files changed, 10 insertions, 18 deletions
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 0f03d7cc56b..b6b2fa88f5b 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -300,6 +300,15 @@ template <typename Predicate> struct cstfp_pred_ty : public Predicate { // /////////////////////////////////////////////////////////////////////////////// +struct is_any_apint { + bool isValue(const APInt &C) { return true; } +}; +/// Match an integer or vector with any integral constant. +/// For vectors, this includes constants with undefined elements. +inline cst_pred_ty<is_any_apint> m_AnyIntegralConstant() { + return cst_pred_ty<is_any_apint>(); +} + struct is_all_ones { bool isValue(const APInt &C) { return C.isAllOnesValue(); } }; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 434b0d59121..327e7ab4fe4 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -145,26 +145,9 @@ static inline bool IsFreeToInvert(Value *V, bool WillInvertAllUses) { return true; // Constants can be considered to be not'ed values. - if (isa<ConstantInt>(V)) + if (match(V, m_AnyIntegralConstant())) return true; - // A vector of constant integers can be inverted easily. - if (V->getType()->isVectorTy() && isa<Constant>(V)) { - unsigned NumElts = V->getType()->getVectorNumElements(); - for (unsigned i = 0; i != NumElts; ++i) { - Constant *Elt = cast<Constant>(V)->getAggregateElement(i); - if (!Elt) - return false; - - if (isa<UndefValue>(Elt)) - continue; - - if (!isa<ConstantInt>(Elt)) - return false; - } - return true; - } - // Compares can be inverted if all of their uses are being modified to use the // ~V. if (isa<CmpInst>(V)) |