Skip to content

Commit 5295b12

Browse files
committed
[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.
1 parent 85e8652 commit 5295b12

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

llvm/include/llvm/IR/PatternMatch.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,14 @@ inline DisjointOr_match<LHS, RHS, true> m_c_DisjointOr(const LHS &L,
12701270
return DisjointOr_match<LHS, RHS, true>(L, R);
12711271
}
12721272

1273+
/// Match either "and" or "or disjoint".
1274+
template <typename LHS, typename RHS>
1275+
inline match_combine_or<BinaryOp_match<LHS, RHS, Instruction::Add>,
1276+
DisjointOr_match<LHS, RHS>>
1277+
m_AddLike(const LHS &L, const RHS &R) {
1278+
return m_CombineOr(m_Add(L, R), m_DisjointOr(L, R));
1279+
}
1280+
12731281
//===----------------------------------------------------------------------===//
12741282
// Class that matches a group of binary opcodes.
12751283
//

llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,7 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
300300
// Canonicalize (X|C1)*MulC -> X*MulC+C1*MulC.
301301
Value *X;
302302
Constant *C1;
303-
if (match(Op0, m_OneUse(m_Add(m_Value(X), m_ImmConstant(C1)))) ||
304-
match(Op0, m_OneUse(m_DisjointOr(m_Value(X), m_ImmConstant(C1))))) {
303+
if (match(Op0, m_OneUse(m_AddLike(m_Value(X), m_ImmConstant(C1))))) {
305304
// C1*MulC simplifies to a tidier constant.
306305
Value *NewC = Builder.CreateMul(C1, MulC);
307306
auto *BOp0 = cast<BinaryOperator>(Op0);

0 commit comments

Comments
 (0)