[llvm] a1b9736 - [PatternMatch] Add m_c_DisjointOr (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 6 05:05:19 PST 2023
Author: Nikita Popov
Date: 2023-12-06T14:05:02+01:00
New Revision: a1b9736e9b588bdb510b49e373006b06f57e61c7
URL: https://github.com/llvm/llvm-project/commit/a1b9736e9b588bdb510b49e373006b06f57e61c7
DIFF: https://github.com/llvm/llvm-project/commit/a1b9736e9b588bdb510b49e373006b06f57e61c7.diff
LOG: [PatternMatch] Add m_c_DisjointOr (NFC)
Add commutative variant of m_DisjointOr.
Added:
Modified:
llvm/include/llvm/IR/PatternMatch.h
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 80655d6c69eed..07f950a9f452a 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -1239,7 +1239,7 @@ inline SpecificBinaryOp_match<LHS, RHS> m_BinOp(unsigned Opcode, const LHS &L,
return SpecificBinaryOp_match<LHS, RHS>(Opcode, L, R);
}
-template <typename LHS, typename RHS>
+template <typename LHS, typename RHS, bool Commutable = false>
struct DisjointOr_match {
LHS L;
RHS R;
@@ -1251,7 +1251,9 @@ struct DisjointOr_match {
assert(PDI->getOpcode() == Instruction::Or && "Only or can be disjoint");
if (!PDI->isDisjoint())
return false;
- return L.match(PDI->getOperand(0)) && R.match(PDI->getOperand(1));
+ return (L.match(PDI->getOperand(0)) && R.match(PDI->getOperand(1))) ||
+ (Commutable && L.match(PDI->getOperand(1)) &&
+ R.match(PDI->getOperand(0)));
}
return false;
}
@@ -1262,6 +1264,12 @@ inline DisjointOr_match<LHS, RHS> m_DisjointOr(const LHS &L, const RHS &R) {
return DisjointOr_match<LHS, RHS>(L, R);
}
+template <typename LHS, typename RHS>
+inline DisjointOr_match<LHS, RHS, true> m_c_DisjointOr(const LHS &L,
+ const RHS &R) {
+ return DisjointOr_match<LHS, RHS, true>(L, R);
+}
+
//===----------------------------------------------------------------------===//
// Class that matches a group of binary opcodes.
//
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 481fcdf181946..f7d196f7f4336 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -3393,9 +3393,8 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
// If the operands have no common bits set:
// or (mul X, Y), X --> add (mul X, Y), X --> mul X, (Y + 1)
- if (match(&I,
- m_c_Or(m_OneUse(m_Mul(m_Value(X), m_Value(Y))), m_Deferred(X))) &&
- cast<PossiblyDisjointInst>(I).isDisjoint()) {
+ if (match(&I, m_c_DisjointOr(m_OneUse(m_Mul(m_Value(X), m_Value(Y))),
+ m_Deferred(X)))) {
Value *IncrementY = Builder.CreateAdd(Y, ConstantInt::get(Ty, 1));
return BinaryOperator::CreateMul(X, IncrementY);
}
More information about the llvm-commits
mailing list