[llvm] r299247 - Do not translate rint into nearbyint, but truncate it like nearbyint.
Joerg Sonnenberger via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 31 12:58:07 PDT 2017
Author: joerg
Date: Fri Mar 31 14:58:07 2017
New Revision: 299247
URL: http://llvm.org/viewvc/llvm-project?rev=299247&view=rev
Log:
Do not translate rint into nearbyint, but truncate it like nearbyint.
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.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/float-shrink-compare.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=299247&r1=299246&r2=299247&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Fri Mar 31 14:58:07 2017
@@ -2091,6 +2091,7 @@ Instruction *InstCombiner::visitCallInst
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))) &&
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=299247&r1=299246&r2=299247&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Fri Mar 31 14:58:07 2017
@@ -2160,8 +2160,9 @@ Value *LibCallSimplifier::optimizeCall(C
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:
Modified: llvm/trunk/test/Transforms/InstCombine/float-shrink-compare.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/float-shrink-compare.ll?rev=299247&r1=299246&r2=299247&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/float-shrink-compare.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/float-shrink-compare.ll Fri Mar 31 14:58:07 2017
@@ -119,7 +119,7 @@ define i32 @test5(float %x, float %y) no
%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) n
%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
}
More information about the llvm-commits
mailing list