From 1cab3bf0046117759cc7891eec66affbbeb5965c Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Fri, 23 Oct 2020 12:32:32 +0100 Subject: [PATCH] [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. --- llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 12 ++++++++---- llvm/lib/Transforms/InstCombine/InstCombineInternal.h | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 13670ff..1e291fb 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -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 Insts; - if (!recognizeBSwapOrBitReverseIdiom(&Or, true, false, Insts)) + SmallVector 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)) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 69811b4..6489327 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -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); -- 2.7.4