[InstCombine] matchFunnelShift - canonicalize to OR(SHL,LSHR). NFCI.

Simplify the shift amount matching code by canonicalizing the shift ops first.
This commit is contained in:
Simon Pilgrim 2020-10-12 15:10:16 +01:00
parent 2d1ee7cae9
commit 02295e6d1a
1 changed files with 13 additions and 9 deletions

View File

@ -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(