Skip to content

Commit

Permalink
[PatternMatch] Add m_AddLike matcher (NFC)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Dec 7, 2023
1 parent 85e8652 commit 5295b12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 8 additions & 0 deletions llvm/include/llvm/IR/PatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5295b12

Please sign in to comment.