llvm.org GIT mirror llvm / 8398512
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 Benjamin Kramer 9 years ago
3 changed file(s) with 11 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
35823582 if (reciprocal.divide(*this, rmNearestTiesToEven) != opOK)
35833583 return false;
35843584
3585 // Avoid multiplication with a denormal, it is not safe on all platforms and
3586 // may be slower than a normal division.
3587 if (reciprocal.significandMSB() + 1 < reciprocal.semantics->precision)
3588 return false;
3589
3590 assert(reciprocal.category == fcNormal &&
3591 reciprocal.significandLSB() == reciprocal.semantics->precision - 1);
3592
35853593 if (inv)
35863594 *inv = reciprocal;
35873595
1212 ret float %div
1313
1414 ; CHECK: @test2
15 ; CHECK-NEXT: fmul float %x, 0x3800000000000000
15 ; CHECK-NEXT: fdiv float %x, 0x47E0000000000000
1616 }
1717
1818 define float @test3(float %x) nounwind readnone ssp {
588588 EXPECT_TRUE(APFloat(1.17549435e-38f).getExactInverse(&inv));
589589 EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(8.5070592e+37f)));
590590
591 // Large float
592 EXPECT_TRUE(APFloat(1.7014118e38f).getExactInverse(&inv));
593 EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(5.8774718e-39f)));
594
591 // Large float, inverse is a denormal.
592 EXPECT_FALSE(APFloat(1.7014118e38f).getExactInverse(0));
595593 // Zero
596594 EXPECT_FALSE(APFloat(0.0).getExactInverse(0));
597595 // Denormalized float