forked from OSchip/llvm-project
[InstSimplify] use m_Specific and commutative matcher to reduce code; NFCI
llvm-svn: 322955
This commit is contained in:
parent
bf4cddaafb
commit
33cb84571f
|
@ -978,17 +978,16 @@ static Value *simplifyDiv(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
|
|||
bool IsSigned = Opcode == Instruction::SDiv;
|
||||
|
||||
// (X * Y) / Y -> X if the multiplication does not overflow.
|
||||
Value *X = nullptr, *Y = nullptr;
|
||||
if (match(Op0, m_Mul(m_Value(X), m_Value(Y))) && (X == Op1 || Y == Op1)) {
|
||||
if (Y != Op1) std::swap(X, Y); // Ensure expression is (X * Y) / Y, Y = Op1
|
||||
OverflowingBinaryOperator *Mul = cast<OverflowingBinaryOperator>(Op0);
|
||||
// If the Mul knows it does not overflow, then we are good to go.
|
||||
Value *X;
|
||||
if (match(Op0, m_c_Mul(m_Value(X), m_Specific(Op1)))) {
|
||||
auto *Mul = cast<OverflowingBinaryOperator>(Op0);
|
||||
// If the Mul does not overflow, then we are good to go.
|
||||
if ((IsSigned && Mul->hasNoSignedWrap()) ||
|
||||
(!IsSigned && Mul->hasNoUnsignedWrap()))
|
||||
return X;
|
||||
// If X has the form X = A / Y then X * Y cannot overflow.
|
||||
if (BinaryOperator *Div = dyn_cast<BinaryOperator>(X))
|
||||
if (Div->getOpcode() == Opcode && Div->getOperand(1) == Y)
|
||||
// If X has the form X = A / Y, then X * Y cannot overflow.
|
||||
if ((IsSigned && match(X, m_SDiv(m_Value(), m_Specific(Op1)))) ||
|
||||
(!IsSigned && match(X, m_UDiv(m_Value(), m_Specific(Op1)))))
|
||||
return X;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue