[llvm] r300030 - [InstCombine][IR] Add a commutable BinOp matcher. Use it to reduce some code. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 11 22:49:29 PDT 2017
Author: ctopper
Date: Wed Apr 12 00:49:28 2017
New Revision: 300030
URL: http://llvm.org/viewvc/llvm-project?rev=300030&view=rev
Log:
[InstCombine][IR] Add a commutable BinOp matcher. Use it to reduce some code. NFC
Modified:
llvm/trunk/include/llvm/IR/PatternMatch.h
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Modified: llvm/trunk/include/llvm/IR/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PatternMatch.h?rev=300030&r1=300029&r2=300030&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/IR/PatternMatch.h Wed Apr 12 00:49:28 2017
@@ -1348,6 +1348,14 @@ template <typename Val_t> inline Signum_
// Matchers for two-operands operators with the operators in either order
//
+/// \brief Matches a Add with LHS and RHS in either order.
+template<typename LHS, typename RHS>
+inline match_combine_or<AnyBinaryOp_match<LHS, RHS>,
+ AnyBinaryOp_match<RHS, LHS>>
+m_c_BinOp(const LHS &L, const RHS &R) {
+ return m_CombineOr(m_BinOp(L, R), m_BinOp(R, L));
+}
+
/// \brief Matches an ICmp with a predicate over LHS and RHS in either order.
/// Does not swap the predicate.
template<typename LHS, typename RHS>
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=300030&r1=300029&r2=300030&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Wed Apr 12 00:49:28 2017
@@ -1272,8 +1272,7 @@ Instruction *InstCombiner::visitAnd(Bina
case Instruction::Sub:
Value *X;
ConstantInt *C1;
- if (match(Op0I, m_BinOp(m_ZExt(m_Value(X)), m_ConstantInt(C1))) ||
- match(Op0I, m_BinOp(m_ConstantInt(C1), m_ZExt(m_Value(X))))) {
+ if (match(Op0I, m_c_BinOp(m_ZExt(m_Value(X)), m_ConstantInt(C1)))) {
if (AndRHSMask.isIntN(X->getType()->getScalarSizeInBits())) {
auto *TruncC1 = ConstantExpr::getTrunc(C1, X->getType());
Value *BinOp;
More information about the llvm-commits
mailing list