aboutsummaryrefslogtreecommitdiff
path: root/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
commit8398512f89623144c8bb45ce9deb4f74f76480fc (patch)
treef36a0e103a6f63fa6537a9eda91358964e17d0d7 /lib/Support/APFloat.cpp
parent546739656ec9469499d3866d87dca6fdbcf2eee0 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128555 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/APFloat.cpp')
-rw-r--r--lib/Support/APFloat.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp
index abe5575318..3a63258cd2 100644
--- a/lib/Support/APFloat.cpp
+++ b/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;