Skip to content

Commit f0b651b

Browse files
committed
[IR] Add m_c_BitwiseLogic in pattern match; NFC
Just a missing matcher that came up in llvm#73362
1 parent 67f2267 commit f0b651b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

llvm/include/llvm/IR/PatternMatch.h

+13-3
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,8 @@ m_NUWAddLike(const LHS &L, const RHS &R) {
13421342
//===----------------------------------------------------------------------===//
13431343
// Class that matches a group of binary opcodes.
13441344
//
1345-
template <typename LHS_t, typename RHS_t, typename Predicate>
1345+
template <typename LHS_t, typename RHS_t, typename Predicate,
1346+
bool Commutable = false>
13461347
struct BinOpPred_match : Predicate {
13471348
LHS_t L;
13481349
RHS_t R;
@@ -1351,8 +1352,10 @@ struct BinOpPred_match : Predicate {
13511352

13521353
template <typename OpTy> bool match(OpTy *V) {
13531354
if (auto *I = dyn_cast<Instruction>(V))
1354-
return this->isOpType(I->getOpcode()) && L.match(I->getOperand(0)) &&
1355-
R.match(I->getOperand(1));
1355+
return this->isOpType(I->getOpcode()) &&
1356+
((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1357+
(Commutable && L.match(I->getOperand(1)) &&
1358+
R.match(I->getOperand(0))));
13561359
return false;
13571360
}
13581361
};
@@ -1419,6 +1422,13 @@ m_BitwiseLogic(const LHS &L, const RHS &R) {
14191422
return BinOpPred_match<LHS, RHS, is_bitwiselogic_op>(L, R);
14201423
}
14211424

1425+
/// Matches bitwise logic operations in either order.
1426+
template <typename LHS, typename RHS>
1427+
inline BinOpPred_match<LHS, RHS, is_bitwiselogic_op>
1428+
m_c_BitwiseLogic(const LHS &L, const RHS &R) {
1429+
return BinOpPred_match<LHS, RHS, is_bitwiselogic_op, true>(L, R);
1430+
}
1431+
14221432
/// Matches integer division operations.
14231433
template <typename LHS, typename RHS>
14241434
inline BinOpPred_match<LHS, RHS, is_idiv_op> m_IDiv(const LHS &L,

0 commit comments

Comments
 (0)