summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-10-31 14:57:23 +0000
committerSanjay Patel <spatel@rotateright.com>2018-10-31 14:57:23 +0000
commit85cba3b6fb4b797d26a16fefb6611c796a71cd1c (patch)
treefad9bfae0d72067f2eef9aba810b9364188dedab /llvm/lib
parent7d6d9eb6889c3f78a4466488d03744e408f39f1c (diff)
downloadbcm5719-llvm-85cba3b6fb4b797d26a16fefb6611c796a71cd1c.tar.gz
bcm5719-llvm-85cba3b6fb4b797d26a16fefb6611c796a71cd1c.zip
[InstSimplify] fold 'fcmp nnan oge X, 0.0' when X is not negative
This re-raises some of the open questions about how to apply and use fast-math-flags in IR from PR38086: https://bugs.llvm.org/show_bug.cgi?id=38086 ...but given the current implementation (no FMF on casts), this is likely the only way to predicate the transform. This is part of solving PR39475: https://bugs.llvm.org/show_bug.cgi?id=39475 Differential Revision: https://reviews.llvm.org/D53874 llvm-svn: 345725
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp4
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp5
2 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index b1381932e7f..efe88507aef 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -3612,6 +3612,10 @@ static Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
}
if (C->isZero()) {
switch (Pred) {
+ case FCmpInst::FCMP_OGE:
+ if (FMF.noNaNs() && CannotBeOrderedLessThanZero(LHS, Q.TLI))
+ return getTrue(RetTy);
+ break;
case FCmpInst::FCMP_UGE:
if (CannotBeOrderedLessThanZero(LHS, Q.TLI))
return getTrue(RetTy);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index d7af4b88a81..d3702a4885c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -5433,8 +5433,8 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
break;
// fabs(x) < 0 --> false
case FCmpInst::FCMP_OLT:
- llvm_unreachable("handled by SimplifyFCmpInst");
- // fabs(x) > 0 --> x != 0
+ llvm_unreachable("fcmp should have simplified");
+ // fabs(x) > 0 --> x != 0
case FCmpInst::FCMP_OGT:
return new FCmpInst(FCmpInst::FCMP_ONE, CI->getArgOperand(0), RHSC);
// fabs(x) <= 0 --> x == 0
@@ -5442,6 +5442,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
return new FCmpInst(FCmpInst::FCMP_OEQ, CI->getArgOperand(0), RHSC);
// fabs(x) >= 0 --> !isnan(x)
case FCmpInst::FCMP_OGE:
+ assert(!I.hasNoNaNs() && "fcmp should have simplified");
return new FCmpInst(FCmpInst::FCMP_ORD, CI->getArgOperand(0), RHSC);
// fabs(x) == 0 --> x == 0
// fabs(x) != 0 --> x != 0
OpenPOWER on IntegriCloud