From 64fa501b1081b5d5c25e5e9639075abb0cb724d9 Mon Sep 17 00:00:00 2001 From: Hal Finkel Date: Sat, 16 Nov 2013 21:29:08 +0000 Subject: Apply the InstCombine fptrunc sqrt optimization to llvm.sqrt InstCombine, in visitFPTrunc, applies the following optimization to sqrt calls: (fptrunc (sqrt (fpext x))) -> (sqrtf x) but does not apply the same optimization to llvm.sqrt. This is a problem because, to enable vectorization, Clang generates llvm.sqrt instead of sqrt in fast-math mode, and because this optimization is being applied to sqrt and not applied to llvm.sqrt, sometimes the fast-math code is slower. This change makes InstCombine apply this optimization to llvm.sqrt as well. This fixes the specific problem in PR17758, although the same underlying issue (optimizations applied to libcalls are not applied to intrinsics) exists for other optimizations in SimplifyLibCalls. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194935 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/InstCombine/double-float-shrink-1.ll | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/Transforms/InstCombine') diff --git a/test/Transforms/InstCombine/double-float-shrink-1.ll b/test/Transforms/InstCombine/double-float-shrink-1.ll index e5448ee007..5cacb591e0 100644 --- a/test/Transforms/InstCombine/double-float-shrink-1.ll +++ b/test/Transforms/InstCombine/double-float-shrink-1.ll @@ -263,6 +263,7 @@ define double @sin_test2(float %f) nounwind readnone { ret double %call ; CHECK: call double @sin(double %conv) } + define float @sqrt_test(float %f) nounwind readnone { ; CHECK: sqrt_test %conv = fpext float %f to double @@ -272,6 +273,15 @@ define float @sqrt_test(float %f) nounwind readnone { ; CHECK: call float @sqrtf(float %f) } +define float @sqrt_int_test(float %f) nounwind readnone { +; CHECK: sqrt_int_test + %conv = fpext float %f to double + %call = call double @llvm.sqrt.f64(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @llvm.sqrt.f32(float %f) +} + define double @sqrt_test2(float %f) nounwind readnone { ; CHECK: sqrt_test2 %conv = fpext float %f to double @@ -331,3 +341,6 @@ declare double @acos(double) nounwind readnone declare double @acosh(double) nounwind readnone declare double @asin(double) nounwind readnone declare double @asinh(double) nounwind readnone + +declare double @llvm.sqrt.f64(double) nounwind readnone + -- cgit v1.2.3