mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
[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:
parent
79d37fda95
commit
ab2599111f
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user