summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorCameron McInally <cameron.mcinally@nyu.edu>2019-05-15 14:31:33 +0000
committerCameron McInally <cameron.mcinally@nyu.edu>2019-05-15 14:31:33 +0000
commit0c82d9b5a2e2eaf19eeb41abaa61646f0de7bec1 (patch)
tree21968e3758ea9728c82d3b041ed586ec07eb375f /llvm/lib/Analysis/InstructionSimplify.cpp
parenteaf4413d2d9d598f093e8c8e84bc01dd33a089e4 (diff)
downloadbcm5719-llvm-0c82d9b5a2e2eaf19eeb41abaa61646f0de7bec1.tar.gz
bcm5719-llvm-0c82d9b5a2e2eaf19eeb41abaa61646f0de7bec1.zip
Teach InstSimplify -X + X --> 0.0 about unary FNeg
Differential Revision: https://reviews.llvm.org/D61916 llvm-svn: 360777
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index febc1d5fe9b..770fdf9054c 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4316,16 +4316,22 @@ static Value *SimplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
(FMF.noSignedZeros() || CannotBeNegativeZero(Op0, Q.TLI)))
return Op0;
- // With nnan: (+/-0.0 - X) + X --> 0.0 (and commuted variant)
+ // With nnan: -X + X --> 0.0 (and commuted variant)
// We don't have to explicitly exclude infinities (ninf): INF + -INF == NaN.
// Negative zeros are allowed because we always end up with positive zero:
// X = -0.0: (-0.0 - (-0.0)) + (-0.0) == ( 0.0) + (-0.0) == 0.0
// X = -0.0: ( 0.0 - (-0.0)) + (-0.0) == ( 0.0) + (-0.0) == 0.0
// X = 0.0: (-0.0 - ( 0.0)) + ( 0.0) == (-0.0) + ( 0.0) == 0.0
// X = 0.0: ( 0.0 - ( 0.0)) + ( 0.0) == ( 0.0) + ( 0.0) == 0.0
- if (FMF.noNaNs() && (match(Op0, m_FSub(m_AnyZeroFP(), m_Specific(Op1))) ||
- match(Op1, m_FSub(m_AnyZeroFP(), m_Specific(Op0)))))
- return ConstantFP::getNullValue(Op0->getType());
+ if (FMF.noNaNs()) {
+ if (match(Op0, m_FSub(m_AnyZeroFP(), m_Specific(Op1))) ||
+ match(Op1, m_FSub(m_AnyZeroFP(), m_Specific(Op0))))
+ return ConstantFP::getNullValue(Op0->getType());
+
+ if (match(Op0, m_FNeg(m_Specific(Op1))) ||
+ match(Op1, m_FNeg(m_Specific(Op0))))
+ return ConstantFP::getNullValue(Op0->getType());
+ }
// (X - Y) + Y --> X
// Y + (X - Y) --> X
OpenPOWER on IntegriCloud