From 948ff87d7de80ba0e959c322f19aa928c4ae7ad4 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 7 Aug 2018 14:36:27 +0000 Subject: [InstSimplify] move minnum/maxnum with common op fold from instcombine llvm-svn: 339144 --- llvm/lib/Analysis/InstructionSimplify.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'llvm/lib/Analysis') diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 494ca656dba..02137a51844 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4805,6 +4805,17 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1, if (match(Op0, m_CombineOr(m_NaN(), m_Undef()))) return Op1; if (match(Op1, m_CombineOr(m_NaN(), m_Undef()))) return Op0; + // Min/max of the same operation with common operand: + // m(m(X, Y)), X --> m(X, Y) (4 commuted variants) + if (auto *M0 = dyn_cast(Op0)) + if (M0->getIntrinsicID() == IID && + (M0->getOperand(0) == Op1 || M0->getOperand(1) == Op1)) + return Op0; + if (auto *M1 = dyn_cast(Op1)) + if (M1->getIntrinsicID() == IID && + (M1->getOperand(0) == Op0 || M1->getOperand(1) == Op0)) + return Op1; + break; default: break; -- cgit v1.2.3