[llvm] 5295b12 - [PatternMatch] Add m_AddLike matcher (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 7 05:45:19 PST 2023
Author: Nikita Popov
Date: 2023-12-07T14:45:12+01:00
New Revision: 5295b12cd056c56c5582da91513966a0a2c8565f
URL: https://github.com/llvm/llvm-project/commit/5295b12cd056c56c5582da91513966a0a2c8565f
DIFF: https://github.com/llvm/llvm-project/commit/5295b12cd056c56c5582da91513966a0a2c8565f.diff
LOG: [PatternMatch] Add m_AddLike matcher (NFC)
This matches either a plain "add" or an "or disjoint" that can
be converted into an add. The AddLike terminology is adopted from
the SDAG layer.
Added:
Modified:
llvm/include/llvm/IR/PatternMatch.h
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 07f950a9f452a..096d1688af3f7 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -1270,6 +1270,14 @@ inline DisjointOr_match<LHS, RHS, true> m_c_DisjointOr(const LHS &L,
return DisjointOr_match<LHS, RHS, true>(L, R);
}
+/// Match either "and" or "or disjoint".
+template <typename LHS, typename RHS>
+inline match_combine_or<BinaryOp_match<LHS, RHS, Instruction::Add>,
+ DisjointOr_match<LHS, RHS>>
+m_AddLike(const LHS &L, const RHS &R) {
+ return m_CombineOr(m_Add(L, R), m_DisjointOr(L, R));
+}
+
//===----------------------------------------------------------------------===//
// Class that matches a group of binary opcodes.
//
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 588bb00462d27..8d5866e98a8ef 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -300,8 +300,7 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
// Canonicalize (X|C1)*MulC -> X*MulC+C1*MulC.
Value *X;
Constant *C1;
- if (match(Op0, m_OneUse(m_Add(m_Value(X), m_ImmConstant(C1)))) ||
- match(Op0, m_OneUse(m_DisjointOr(m_Value(X), m_ImmConstant(C1))))) {
+ if (match(Op0, m_OneUse(m_AddLike(m_Value(X), m_ImmConstant(C1))))) {
// C1*MulC simplifies to a tidier constant.
Value *NewC = Builder.CreateMul(C1, MulC);
auto *BOp0 = cast<BinaryOperator>(Op0);
More information about the llvm-commits
mailing list