[llvm-commits] [llvm] r128555 - in /llvm/trunk: lib/Support/APFloat.cpp test/Transforms/InstCombine/fdiv.ll unittests/ADT/APFloatTest.cpp

Benjamin Kramer benny.kra at googlemail.com
Wed Mar 30 10:02:54 PDT 2011


Author: d0k
Date: Wed Mar 30 12:02:54 2011
New Revision: 128555

URL: http://llvm.org/viewvc/llvm-project?rev=128555&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Support/APFloat.cpp
    llvm/trunk/test/Transforms/InstCombine/fdiv.ll
    llvm/trunk/unittests/ADT/APFloatTest.cpp

Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=128555&r1=128554&r2=128555&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Wed Mar 30 12:02:54 2011
@@ -3583,6 +3583,14 @@
   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;
 

Modified: llvm/trunk/test/Transforms/InstCombine/fdiv.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fdiv.ll?rev=128555&r1=128554&r2=128555&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fdiv.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fdiv.ll Wed Mar 30 12:02:54 2011
@@ -13,7 +13,7 @@
   ret float %div
 
 ; CHECK: @test2
-; CHECK-NEXT: fmul float %x, 0x3800000000000000
+; CHECK-NEXT: fdiv float %x, 0x47E0000000000000
 }
 
 define float @test3(float %x) nounwind readnone ssp {

Modified: llvm/trunk/unittests/ADT/APFloatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APFloatTest.cpp?rev=128555&r1=128554&r2=128555&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APFloatTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APFloatTest.cpp Wed Mar 30 12:02:54 2011
@@ -589,10 +589,8 @@
   EXPECT_TRUE(APFloat(1.17549435e-38f).getExactInverse(&inv));
   EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(8.5070592e+37f)));
 
-  // Large float
-  EXPECT_TRUE(APFloat(1.7014118e38f).getExactInverse(&inv));
-  EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(5.8774718e-39f)));
-
+  // Large float, inverse is a denormal.
+  EXPECT_FALSE(APFloat(1.7014118e38f).getExactInverse(0));
   // Zero
   EXPECT_FALSE(APFloat(0.0).getExactInverse(0));
   // Denormalized float





More information about the llvm-commits mailing list