@@ -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 >
13461347struct 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.
14231433template <typename LHS, typename RHS>
14241434inline BinOpPred_match<LHS, RHS, is_idiv_op> m_IDiv (const LHS &L,
0 commit comments