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
This commit is contained in:
Benjamin Kramer
2011-03-30 17:02:54 +00:00
parent 546739656e
commit 8398512f89
3 changed files with 11 additions and 5 deletions

View File

@@ -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;