summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2018-10-19 19:01:26 +0000
committerThomas Lively <tlively@google.com>2018-10-19 19:01:26 +0000
commitc339250e122a3d5e6148f994d7f69eae95c31aa6 (patch)
treeb8883babc81ed815b7dad1f976a198aeb0f3b47f /llvm/lib/Analysis/InstructionSimplify.cpp
parentc3d447fe26f9bf742625f70feadd102c1eed0d99 (diff)
downloadbcm5719-llvm-c339250e122a3d5e6148f994d7f69eae95c31aa6.tar.gz
bcm5719-llvm-c339250e122a3d5e6148f994d7f69eae95c31aa6.zip
[InstCombine] InstCombine and InstSimplify for minimum and maximum
Summary: Depends on D52765 Reviewers: aheejin, dschuff Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D52766 llvm-svn: 344799
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 86f5652f830..6ff72638512 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4827,13 +4827,24 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
}
break;
case Intrinsic::maxnum:
- case Intrinsic::minnum: {
+ case Intrinsic::minnum:
+ case Intrinsic::maximum:
+ case Intrinsic::minimum: {
// If the arguments are the same, this is a no-op.
if (Op0 == Op1) return Op0;
- // If one argument is NaN or undef, return the other argument.
- if (match(Op0, m_CombineOr(m_NaN(), m_Undef()))) return Op1;
- if (match(Op1, m_CombineOr(m_NaN(), m_Undef()))) return Op0;
+ // If one argument is undef, return the other argument.
+ if (match(Op0, m_Undef()))
+ return Op1;
+ if (match(Op1, m_Undef()))
+ return Op0;
+
+ // If one argument is NaN, return other or NaN appropriately.
+ bool PropagateNaN = IID == Intrinsic::minimum || IID == Intrinsic::maximum;
+ if (match(Op0, m_NaN()))
+ return PropagateNaN ? Op0 : Op1;
+ if (match(Op1, m_NaN()))
+ return PropagateNaN ? Op1 : Op0;
// Min/max of the same operation with common operand:
// m(m(X, Y)), X --> m(X, Y) (4 commuted variants)
@@ -4846,9 +4857,9 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
(M1->getOperand(0) == Op0 || M1->getOperand(1) == Op0))
return Op1;
- // minnum(X, -Inf) --> -Inf (and commuted variant)
- // maxnum(X, +Inf) --> +Inf (and commuted variant)
- bool UseNegInf = IID == Intrinsic::minnum;
+ // min(X, -Inf) --> -Inf (and commuted variant)
+ // max(X, +Inf) --> +Inf (and commuted variant)
+ bool UseNegInf = IID == Intrinsic::minnum || IID == Intrinsic::minimum;
const APFloat *C;
if ((match(Op0, m_APFloat(C)) && C->isInfinity() &&
C->isNegative() == UseNegInf) ||
OpenPOWER on IntegriCloud