diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-01-19 16:12:55 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-01-19 16:12:55 +0000 |
commit | 33cb84571f088f12154b7a86bd3d327de4bab269 (patch) | |
tree | 7b5a18db4995a11d6b609b5c22d0580758c4aab2 /llvm/lib/Analysis/InstructionSimplify.cpp | |
parent | bf4cddaafb1e0f730509ff13883f22fb4620b304 (diff) | |
download | bcm5719-llvm-33cb84571f088f12154b7a86bd3d327de4bab269.tar.gz bcm5719-llvm-33cb84571f088f12154b7a86bd3d327de4bab269.zip |
[InstSimplify] use m_Specific and commutative matcher to reduce code; NFCI
llvm-svn: 322955
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 9f8e8c9a853..6c6b1cfe720 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -978,18 +978,17 @@ 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) - return X; + // 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; } // (X rem Y) / Y -> 0 |