diff options
author | Nikita Popov <npopov@redhat.com> | 2023-12-01 14:25:16 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-12-01 14:26:15 +0100 |
commit | da86d4a8c956f0fcee21444eb6de9f05d39d6574 (patch) | |
tree | 5bbcbd0cb4b155e2779b22be382aab495392924e /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 977af4252d1d60a1e9c546f0e4328b1a646ef635 (diff) | |
download | llvm-da86d4a8c956f0fcee21444eb6de9f05d39d6574.zip llvm-da86d4a8c956f0fcee21444eb6de9f05d39d6574.tar.gz llvm-da86d4a8c956f0fcee21444eb6de9f05d39d6574.tar.bz2 |
[ValueTracking] Reduce duplication in haveNoCommonBitsSet() (NFC)
Extract a function and call it with both operand orders, so that
we don't have to explicitly commute every single pattern.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index d8a72c9..8c29c24 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -186,47 +186,30 @@ KnownBits llvm::computeKnownBits(const Value *V, const APInt &DemandedElts, SimplifyQuery(DL, DT, AC, safeCxtI(V, CxtI), UseInstrInfo)); } -bool llvm::haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache, - const WithCache<const Value *> &RHSCache, - const SimplifyQuery &SQ) { - const Value *LHS = LHSCache.getValue(); - const Value *RHS = RHSCache.getValue(); - - assert(LHS->getType() == RHS->getType() && - "LHS and RHS should have the same type"); - assert(LHS->getType()->isIntOrIntVectorTy() && - "LHS and RHS should be integers"); +static bool haveNoCommonBitsSetSpecialCases(const Value *LHS, + const Value *RHS) { // Look for an inverted mask: (X & ~M) op (Y & M). { Value *M; if (match(LHS, m_c_And(m_Not(m_Value(M)), m_Value())) && match(RHS, m_c_And(m_Specific(M), m_Value()))) return true; - if (match(RHS, m_c_And(m_Not(m_Value(M)), m_Value())) && - match(LHS, m_c_And(m_Specific(M), m_Value()))) - return true; } // X op (Y & ~X) - if (match(RHS, m_c_And(m_Not(m_Specific(LHS)), m_Value())) || - match(LHS, m_c_And(m_Not(m_Specific(RHS)), m_Value()))) + if (match(RHS, m_c_And(m_Not(m_Specific(LHS)), m_Value()))) return true; // X op ((X & Y) ^ Y) -- this is the canonical form of the previous pattern // for constant Y. Value *Y; - if (match(RHS, - m_c_Xor(m_c_And(m_Specific(LHS), m_Value(Y)), m_Deferred(Y))) || - match(LHS, m_c_Xor(m_c_And(m_Specific(RHS), m_Value(Y)), m_Deferred(Y)))) + if (match(RHS, m_c_Xor(m_c_And(m_Specific(LHS), m_Value(Y)), m_Deferred(Y)))) return true; // Peek through extends to find a 'not' of the other side: // (ext Y) op ext(~Y) - // (ext ~Y) op ext(Y) - if ((match(LHS, m_ZExtOrSExt(m_Value(Y))) && - match(RHS, m_ZExtOrSExt(m_Not(m_Specific(Y))))) || - (match(RHS, m_ZExtOrSExt(m_Value(Y))) && - match(LHS, m_ZExtOrSExt(m_Not(m_Specific(Y)))))) + if (match(LHS, m_ZExtOrSExt(m_Value(Y))) && + match(RHS, m_ZExtOrSExt(m_Not(m_Specific(Y))))) return true; // Look for: (A & B) op ~(A | B) @@ -235,11 +218,26 @@ bool llvm::haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache, if (match(LHS, m_And(m_Value(A), m_Value(B))) && match(RHS, m_Not(m_c_Or(m_Specific(A), m_Specific(B))))) return true; - if (match(RHS, m_And(m_Value(A), m_Value(B))) && - match(LHS, m_Not(m_c_Or(m_Specific(A), m_Specific(B))))) - return true; } + return false; +} + +bool llvm::haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache, + const WithCache<const Value *> &RHSCache, + const SimplifyQuery &SQ) { + const Value *LHS = LHSCache.getValue(); + const Value *RHS = RHSCache.getValue(); + + assert(LHS->getType() == RHS->getType() && + "LHS and RHS should have the same type"); + assert(LHS->getType()->isIntOrIntVectorTy() && + "LHS and RHS should be integers"); + + if (haveNoCommonBitsSetSpecialCases(LHS, RHS) || + haveNoCommonBitsSetSpecialCases(RHS, LHS)) + return true; + return KnownBits::haveNoCommonBitsSet(LHSCache.getKnownBits(SQ), RHSCache.getKnownBits(SQ)); } |