[llvm] 02295e6 - [InstCombine] matchFunnelShift - canonicalize to OR(SHL,LSHR). NFCI.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 12 07:23:33 PDT 2020
Author: Simon Pilgrim
Date: 2020-10-12T15:10:59+01:00
New Revision: 02295e6d1a1559f0689aeca09d98f468e3f29d9a
URL: https://github.com/llvm/llvm-project/commit/02295e6d1a1559f0689aeca09d98f468e3f29d9a
DIFF: https://github.com/llvm/llvm-project/commit/02295e6d1a1559f0689aeca09d98f468e3f29d9a.diff
LOG: [InstCombine] matchFunnelShift - canonicalize to OR(SHL,LSHR). NFCI.
Simplify the shift amount matching code by canonicalizing the shift ops first.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 52b81ad2164a..06168e2424ef 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2067,13 +2067,19 @@ static Instruction *matchFunnelShift(Instruction &Or) {
Value *ShVal0, *ShVal1, *ShAmt0, *ShAmt1;
if (!match(Or0, m_OneUse(m_LogicalShift(m_Value(ShVal0), m_Value(ShAmt0)))) ||
- !match(Or1, m_OneUse(m_LogicalShift(m_Value(ShVal1), m_Value(ShAmt1)))))
+ !match(Or1, m_OneUse(m_LogicalShift(m_Value(ShVal1), m_Value(ShAmt1)))) ||
+ Or0->getOpcode() == Or1->getOpcode())
return nullptr;
- BinaryOperator::BinaryOps ShiftOpcode0 = Or0->getOpcode();
- BinaryOperator::BinaryOps ShiftOpcode1 = Or1->getOpcode();
- if (ShiftOpcode0 == ShiftOpcode1)
- return nullptr;
+ // Canonicalize to or(shl(ShVal0, ShAmt0), lshr(ShVal1, ShAmt1)).
+ if (Or0->getOpcode() == BinaryOperator::LShr) {
+ std::swap(Or0, Or1);
+ std::swap(ShVal0, ShVal1);
+ std::swap(ShAmt0, ShAmt1);
+ }
+ assert(Or0->getOpcode() == BinaryOperator::Shl &&
+ Or1->getOpcode() == BinaryOperator::LShr &&
+ "Illegal or(shift,shift) pair");
// Match the shift amount operands for a funnel shift pattern. This always
// matches a subtraction on the R operand.
@@ -2124,16 +2130,14 @@ static Instruction *matchFunnelShift(Instruction &Or) {
};
Value *ShAmt = matchShiftAmount(ShAmt0, ShAmt1, Width);
- bool SubIsOnLHS = false;
+ bool IsFshl = true; // Sub on LSHR.
if (!ShAmt) {
ShAmt = matchShiftAmount(ShAmt1, ShAmt0, Width);
- SubIsOnLHS = true;
+ IsFshl = false; // Sub on SHL.
}
if (!ShAmt)
return nullptr;
- bool IsFshl = (!SubIsOnLHS && ShiftOpcode0 == BinaryOperator::Shl) ||
- (SubIsOnLHS && ShiftOpcode1 == BinaryOperator::Shl);
Intrinsic::ID IID = IsFshl ? Intrinsic::fshl : Intrinsic::fshr;
Function *F = Intrinsic::getDeclaration(Or.getModule(), IID, Or.getType());
return IntrinsicInst::Create(
More information about the llvm-commits
mailing list