[PATCH] D97056: [InstCombine] matchBSwapOrBitReverse - remove pattern matching early-out. NFCI.
Simon Pilgrim via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 19 08:17:58 PST 2021
RKSimon created this revision.
RKSimon added reviewers: spatel, nikic, lebedev.ri.
Herald added a subscriber: hiraditya.
RKSimon requested review of this revision.
Herald added a project: LLVM.
recognizeBSwapOrBitReverseIdiom + collectBitParts have pattern matching to bail if a bswap/bitreverse pattern isn't possible - we should be able to rely on this instead.
This is part of a cleanup towards letting matchBSwapOrBitReverse /recognizeBSwapOrBitReverseIdiom use 'root' instructions that aren't ORs (FSHL/FSHRs in particular which can be prematurely created).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97056
Files:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
Index: llvm/lib/Transforms/InstCombine/InstCombineInternal.h
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -715,10 +715,10 @@
Instruction *PromoteCastOfAllocation(BitCastInst &CI, AllocaInst &AI);
bool mergeStoreIntoSuccessor(StoreInst &SI);
- /// Given an 'or' instruction, check to see if it is part of a
+ /// Given an initial instruction, check to see if it is root of a
/// bswap/bitreverse idiom. If so, return the equivalent bswap/bitreverse
/// intrinsic.
- Instruction *matchBSwapOrBitReverse(BinaryOperator &Or, bool MatchBSwaps,
+ Instruction *matchBSwapOrBitReverse(Instruction &I, bool MatchBSwaps,
bool MatchBitReversals);
Instruction *SimplifyAnyMemTransfer(AnyMemTransferInst *MI);
Index: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -1990,45 +1990,11 @@
return nullptr;
}
-Instruction *InstCombinerImpl::matchBSwapOrBitReverse(BinaryOperator &Or,
+Instruction *InstCombinerImpl::matchBSwapOrBitReverse(Instruction &I,
bool MatchBSwaps,
bool MatchBitReversals) {
- assert(Or.getOpcode() == Instruction::Or && "bswap requires an 'or'");
- Value *Op0 = Or.getOperand(0), *Op1 = Or.getOperand(1);
-
- // Look through zero extends.
- if (Instruction *Ext = dyn_cast<ZExtInst>(Op0))
- Op0 = Ext->getOperand(0);
-
- if (Instruction *Ext = dyn_cast<ZExtInst>(Op1))
- Op1 = Ext->getOperand(0);
-
- // (A | B) | C and A | (B | C) -> bswap if possible.
- bool OrWithOrs = match(Op0, m_Or(m_Value(), m_Value())) ||
- match(Op1, m_Or(m_Value(), m_Value()));
-
- // (A >> B) | C and (A << B) | C -> bswap if possible.
- bool OrWithShifts = match(Op0, m_LogicalShift(m_Value(), m_Value())) ||
- match(Op1, m_LogicalShift(m_Value(), m_Value()));
-
- // (A & B) | C and A | (B & C) -> bswap if possible.
- bool OrWithAnds = match(Op0, m_And(m_Value(), m_Value())) ||
- match(Op1, m_And(m_Value(), m_Value()));
-
- // fshl(A,B,C) | D and A | fshl(B,C,D) -> bswap if possible.
- // fshr(A,B,C) | D and A | fshr(B,C,D) -> bswap if possible.
- bool OrWithFunnels = match(Op0, m_FShl(m_Value(), m_Value(), m_Value())) ||
- match(Op0, m_FShr(m_Value(), m_Value(), m_Value())) ||
- match(Op0, m_FShl(m_Value(), m_Value(), m_Value())) ||
- match(Op0, m_FShr(m_Value(), m_Value(), m_Value()));
-
- // TODO: Do we need all these filtering checks or should we just rely on
- // recognizeBSwapOrBitReverseIdiom + collectBitParts to reject them quickly?
- if (!OrWithOrs && !OrWithShifts && !OrWithAnds && !OrWithFunnels)
- return nullptr;
-
SmallVector<Instruction *, 4> Insts;
- if (!recognizeBSwapOrBitReverseIdiom(&Or, MatchBSwaps, MatchBitReversals,
+ if (!recognizeBSwapOrBitReverseIdiom(&I, MatchBSwaps, MatchBitReversals,
Insts))
return nullptr;
Instruction *LastInst = Insts.pop_back_val();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97056.324987.patch
Type: text/x-patch
Size: 3488 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210219/47dab9fb/attachment.bin>
More information about the llvm-commits
mailing list