summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/APFloat.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2011-03-30 17:02:54 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2011-03-30 17:02:54 +0000
commitaf0ed953c57d1a29e8ad08cec039df7c0d59e193 (patch)
treeeca022d79b46f963cac817b76ba07ebef84e036e /llvm/lib/Support/APFloat.cpp
parent20688ccc4869f7d85681cbbf13e3878784d6aab8 (diff)
downloadbcm5719-llvm-af0ed953c57d1a29e8ad08cec039df7c0d59e193.tar.gz
bcm5719-llvm-af0ed953c57d1a29e8ad08cec039df7c0d59e193.zip
Avoid turning a floating point division with a constant power of two into a denormal multiplication.
Some platforms may treat denormals as zero, on other platforms multiplication with a subnormal is slower than dividing by a normal. llvm-svn: 128555
Diffstat (limited to 'llvm/lib/Support/APFloat.cpp')
-rw-r--r--llvm/lib/Support/APFloat.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index abe55753181..3a63258cd26 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -3583,6 +3583,14 @@ bool APFloat::getExactInverse(APFloat *inv) const {
if (reciprocal.divide(*this, rmNearestTiesToEven) != opOK)
return false;
+ // Avoid multiplication with a denormal, it is not safe on all platforms and
+ // may be slower than a normal division.
+ if (reciprocal.significandMSB() + 1 < reciprocal.semantics->precision)
+ return false;
+
+ assert(reciprocal.category == fcNormal &&
+ reciprocal.significandLSB() == reciprocal.semantics->precision - 1);
+
if (inv)
*inv = reciprocal;
OpenPOWER on IntegriCloud