[InstCombine] matchBSwapOrBitReverse - expose bswap/bitreverse matching flags.

matchBSwapOrBitReverse was hardcoded to just match bswaps - we're going to need to expose the ability to match bitreverse as well, so make this part of the function call.
This commit is contained in:
Simon Pilgrim 2020-10-23 12:32:32 +01:00
parent 19a13bf538
commit 1cab3bf004
2 changed files with 10 additions and 5 deletions

View File

@ -1985,7 +1985,9 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
return nullptr;
}
Instruction *InstCombinerImpl::matchBSwapOrBitReverse(BinaryOperator &Or) {
Instruction *InstCombinerImpl::matchBSwapOrBitReverse(BinaryOperator &Or,
bool MatchBSwaps,
bool MatchBitReversals) {
assert(Or.getOpcode() == Instruction::Or && "bswap requires an 'or'");
Value *Op0 = Or.getOperand(0), *Op1 = Or.getOperand(1);
@ -2011,8 +2013,9 @@ Instruction *InstCombinerImpl::matchBSwapOrBitReverse(BinaryOperator &Or) {
if (!OrWithOrs && !OrWithShifts && !OrWithAnds)
return nullptr;
SmallVector<Instruction*, 4> Insts;
if (!recognizeBSwapOrBitReverseIdiom(&Or, true, false, Insts))
SmallVector<Instruction *, 4> Insts;
if (!recognizeBSwapOrBitReverseIdiom(&Or, MatchBSwaps, MatchBitReversals,
Insts))
return nullptr;
Instruction *LastInst = Insts.pop_back_val();
LastInst->removeFromParent();
@ -2563,7 +2566,8 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
if (Instruction *FoldedLogic = foldBinOpIntoSelectOrPhi(I))
return FoldedLogic;
if (Instruction *BSwap = matchBSwapOrBitReverse(I))
if (Instruction *BSwap = matchBSwapOrBitReverse(I, /*MatchBSwaps*/ true,
/*MatchBitReversals*/ false))
return BSwap;
if (Instruction *Funnel = matchFunnelShift(I, *this))

View File

@ -724,7 +724,8 @@ public:
/// Given an 'or' instruction, check to see if it is part of a
/// bswap/bitreverse idiom. If so, return the equivalent bswap/bitreverse
/// intrinsic.
Instruction *matchBSwapOrBitReverse(BinaryOperator &Or);
Instruction *matchBSwapOrBitReverse(BinaryOperator &Or, bool MatchBSwaps,
bool MatchBitReversals);
Instruction *SimplifyAnyMemTransfer(AnyMemTransferInst *MI);
Instruction *SimplifyAnyMemSet(AnyMemSetInst *MI);