From 848309da7c1861b328d775b28b03d8f687ebeb5c Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 23 Oct 2014 21:52:45 +0000 Subject: Handle sqrt() shrinking in SimplifyLibCalls like any other call This patch removes a chunk of special case logic for folding (float)sqrt((double)x) -> sqrtf(x) in InstCombineCasts and handles it in the mainstream path of SimplifyLibCalls. No functional change intended, but I loosened the restriction on the existing sqrt testcases to allow for this optimization even without unsafe-fp-math because that's the existing behavior. I also added a missing test case for not shrinking the llvm.sqrt.f64 intrinsic in case the result is used as a double. Differential Revision: http://reviews.llvm.org/D5919 llvm-svn: 220514 --- .../InstCombine/double-float-shrink-1.ll | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'llvm/test/Transforms/InstCombine/double-float-shrink-1.ll') diff --git a/llvm/test/Transforms/InstCombine/double-float-shrink-1.ll b/llvm/test/Transforms/InstCombine/double-float-shrink-1.ll index 9b422b77296..63a02bbd857 100644 --- a/llvm/test/Transforms/InstCombine/double-float-shrink-1.ll +++ b/llvm/test/Transforms/InstCombine/double-float-shrink-1.ll @@ -279,6 +279,14 @@ define float @sqrt_test(float %f) { ; CHECK: call float @sqrtf(float %f) } +define double @sqrt_test2(float %f) { + %conv = fpext float %f to double + %call = call double @sqrt(double %conv) + ret double %call +; CHECK-LABEL: sqrt_test2 +; CHECK: call double @sqrt(double %conv) +} + define float @sqrt_int_test(float %f) { %conv = fpext float %f to double %call = call double @llvm.sqrt.f64(double %conv) @@ -288,13 +296,14 @@ define float @sqrt_int_test(float %f) { ; CHECK: call float @llvm.sqrt.f32(float %f) } -define double @sqrt_test2(float %f) { +define double @sqrt_int_test2(float %f) { %conv = fpext float %f to double - %call = call double @sqrt(double %conv) + %call = call double @llvm.sqrt.f64(double %conv) ret double %call -; CHECK-LABEL: sqrt_test2 -; CHECK: call double @sqrt(double %conv) +; CHECK-LABEL: sqrt_int_test2 +; CHECK: call double @llvm.sqrt.f64(double %conv) } + define float @tan_test(float %f) { %conv = fpext float %f to double %call = call double @tan(double %conv) @@ -330,7 +339,12 @@ define double @tanh_test2(float %f) { declare double @tanh(double) #1 declare double @tan(double) #1 -declare double @sqrt(double) #1 + +; sqrt is a special case: the shrinking optimization +; is valid even without unsafe-fp-math. +declare double @sqrt(double) +declare double @llvm.sqrt.f64(double) + declare double @sin(double) #1 declare double @log2(double) #1 declare double @log1p(double) #1 @@ -348,6 +362,5 @@ declare double @acosh(double) #1 declare double @asin(double) #1 declare double @asinh(double) #1 -declare double @llvm.sqrt.f64(double) #1 attributes #1 = { "unsafe-fp-math"="true" } -- cgit v1.2.3