[llvm] [InstCombine] Add ctpop(A | B) + ctpop(A & B) -> ctpop(A) + ctpop(B) (PR #79089)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 22 19:59:57 PST 2024
================
@@ -1718,6 +1718,25 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
Builder.CreateIntrinsic(Intrinsic::umax, {I.getType()}, {A, B}));
}
+ // ctpop(A | B) + ctpop(A & B) -> ctpop(A) + ctpop(B)
+ if ((match(LHS, m_OneUse(m_Intrinsic<Intrinsic::ctpop>(
+ m_And(m_Value(A), m_Value(B))))) &&
+ (match(RHS, m_OneUse(m_Intrinsic<Intrinsic::ctpop>(
+ m_Or(m_Specific(A), m_Specific(B))))) ||
+ match(RHS, m_OneUse(m_Intrinsic<Intrinsic::ctpop>(
+ m_Or(m_Specific(B), m_Specific(A))))))) ||
+ (match(LHS, m_OneUse(m_Intrinsic<Intrinsic::ctpop>(
+ m_Or(m_Value(A), m_Value(B))))) &&
+ (match(RHS, m_OneUse(m_Intrinsic<Intrinsic::ctpop>(
+ m_And(m_Specific(A), m_Specific(B))))) ||
+ match(RHS, m_OneUse(m_Intrinsic<Intrinsic::ctpop>(
+ m_And(m_Specific(B), m_Specific(A)))))))) {
----------------
dtcxzyw wrote:
```suggestion
if (match(&I, m_c_Add(m_OneUse(m_Intrinsic<Intrinsic::ctpop>(
m_And(m_Value(A), m_Value(B))))), mOneUse(m_Intrinsic<Intrinsic::ctpop>(
m_c_Or(m_Specific(A), m_Specific(B)))))))) {
```
https://github.com/llvm/llvm-project/pull/79089
More information about the llvm-commits
mailing list