]> granicus.if.org Git - llvm/commitdiff
Do not translate rint into nearbyint, but truncate it like nearbyint.
authorJoerg Sonnenberger <joerg@bec.de>
Fri, 31 Mar 2017 19:58:07 +0000 (19:58 +0000)
committerJoerg Sonnenberger <joerg@bec.de>
Fri, 31 Mar 2017 19:58:07 +0000 (19:58 +0000)
A common way to implement nearbyint is by fiddling with the floating
point environment and calling rint. This is used at least by the BSD
libm and musl. As such, canonicalizing the latter to the former will
create infinite loops for libm and generally pessimize performance, at
least when the generic C versions are used.

This change preserves the rint in the libcall translation and also
handles the domain truncation logic, so that rint with float argument
will be reduced to rintf etc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299247 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCalls.cpp
lib/Transforms/Utils/SimplifyLibCalls.cpp
test/Transforms/InstCombine/float-shrink-compare.ll

index 71ca14dee58473a33a1c509d803617dc74724874..af4c9ac75378d5ad12388144bfff008e9b8721c8 100644 (file)
@@ -2091,6 +2091,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
   case Intrinsic::floor:
   case Intrinsic::round:
   case Intrinsic::nearbyint:
+  case Intrinsic::rint:
   case Intrinsic::trunc: {
     Value *ExtSrc;
     if (match(II->getArgOperand(0), m_FPExt(m_Value(ExtSrc))) &&
index fa0ef1729cf59d82fdf3e2b30290f45dc9d66663..cd2d7f91920d7a8e5a47eb855d244b86bafaff86 100644 (file)
@@ -2160,8 +2160,9 @@ Value *LibCallSimplifier::optimizeCall(CallInst *CI) {
     case LibFunc_round:
       return replaceUnaryCall(CI, Builder, Intrinsic::round);
     case LibFunc_nearbyint:
-    case LibFunc_rint:
       return replaceUnaryCall(CI, Builder, Intrinsic::nearbyint);
+    case LibFunc_rint:
+      return replaceUnaryCall(CI, Builder, Intrinsic::rint);
     case LibFunc_trunc:
       return replaceUnaryCall(CI, Builder, Intrinsic::trunc);
     case LibFunc_acos:
index a98f4cd1cb422019d98c7c9ab3e539879e5564c2..e0925952bf44d533463c9e7b040a244dd74dc5f3 100644 (file)
@@ -119,7 +119,7 @@ define i32 @test5(float %x, float %y) nounwind uwtable {
   %cmp.ext = zext i1 %cmp to i32
   ret i32 %cmp.ext
 ; CHECK-LABEL: @test5(
-; CHECK-NEXT: %rint = call float @llvm.nearbyint.f32(float %x)
+; CHECK-NEXT: %rint = call float @llvm.rint.f32(float %x)
 ; CHECK-NEXT: fcmp oeq float %rint, %y
 }
 
@@ -276,7 +276,7 @@ define i32 @test12(float %x, float %y) nounwind uwtable {
   %cmp.ext = zext i1 %cmp to i32
   ret i32 %cmp.ext
 ; CHECK-LABEL: @test12(
-; CHECK-NEXT: %rint = call float @llvm.nearbyint.f32(float %x)
+; CHECK-NEXT: %rint = call float @llvm.rint.f32(float %x)
 ; CHECK-NEXT: fcmp oeq float %rint, %y
 }