summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-08-09 22:20:44 +0000
committerSanjay Patel <spatel@rotateright.com>2018-08-09 22:20:44 +0000
commitc6944f795d846ae55f8375dd0f8f8ef2045d4cfb (patch)
tree3cf71c4520086ee23bfaa13682383a4742e64ad6 /llvm/lib
parent94abc57e3751f591fdb0655419eb129252d1f9c7 (diff)
downloadbcm5719-llvm-c6944f795d846ae55f8375dd0f8f8ef2045d4cfb.tar.gz
bcm5719-llvm-c6944f795d846ae55f8375dd0f8f8ef2045d4cfb.zip
[InstSimplify] move minnum/maxnum with Inf folds from instcombine
llvm-svn: 339396
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp17
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp35
2 files changed, 16 insertions, 36 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 13805437b54..9d317b46b9e 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4812,7 +4812,7 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
}
break;
case Intrinsic::maxnum:
- case Intrinsic::minnum:
+ case Intrinsic::minnum: {
// If the arguments are the same, this is a no-op.
if (Op0 == Op1) return Op0;
@@ -4831,7 +4831,22 @@ 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;
+ const APFloat *C;
+ if ((match(Op0, m_APFloat(C)) && C->isInfinity() &&
+ C->isNegative() == UseNegInf) ||
+ (match(Op1, m_APFloat(C)) && C->isInfinity() &&
+ C->isNegative() == UseNegInf))
+ return ConstantFP::getInfinity(ReturnType, UseNegInf);
+
+ // TODO: minnum(nnan x, inf) -> x
+ // TODO: minnum(nnan ninf x, flt_max) -> x
+ // TODO: maxnum(nnan x, -inf) -> x
+ // TODO: maxnum(nnan ninf x, -flt_max) -> x
break;
+ }
default:
break;
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index dcd080e3305..310b87e931c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1133,37 +1133,6 @@ static Value *simplifyX86vpcom(const IntrinsicInst &II,
return nullptr;
}
-static Value *simplifyMinnumMaxnum(const IntrinsicInst &II) {
- Value *Arg0 = II.getArgOperand(0);
- Value *Arg1 = II.getArgOperand(1);
-
- const auto *C1 = dyn_cast<ConstantFP>(Arg1);
-
- // fmin(x, nan) -> x
- if (C1 && C1->isNaN())
- return Arg0;
-
- if (II.getIntrinsicID() == Intrinsic::minnum) {
- // TODO: fmin(nnan x, inf) -> x
- // TODO: fmin(nnan ninf x, flt_max) -> x
- if (C1 && C1->isInfinity()) {
- // fmin(x, -inf) -> -inf
- if (C1->isNegative())
- return Arg1;
- }
- } else {
- assert(II.getIntrinsicID() == Intrinsic::maxnum);
- // TODO: fmax(nnan x, -inf) -> x
- // TODO: fmax(nnan ninf x, -flt_max) -> x
- if (C1 && C1->isInfinity()) {
- // fmax(x, inf) -> inf
- if (!C1->isNegative())
- return Arg1;
- }
- }
- return nullptr;
-}
-
static bool maskIsAllOneOrUndef(Value *Mask) {
auto *ConstMask = dyn_cast<Constant>(Mask);
if (!ConstMask)
@@ -2000,10 +1969,6 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
return II;
}
- // FIXME: Simplifications should be in instsimplify.
- if (Value *V = simplifyMinnumMaxnum(*II))
- return replaceInstUsesWith(*II, V);
-
Value *X, *Y;
if (match(Arg0, m_FNeg(m_Value(X))) && match(Arg1, m_FNeg(m_Value(Y))) &&
(Arg0->hasOneUse() || Arg1->hasOneUse())) {
OpenPOWER on IntegriCloud