1 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=sse2 | FileCheck %s
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=avx -recip=sqrtf,vec-sqrtf | FileCheck %s --check-prefix=ESTIMATE
4 declare double @__sqrt_finite(double) #0
5 declare float @__sqrtf_finite(float) #0
6 declare x86_fp80 @__sqrtl_finite(x86_fp80) #0
7 declare float @llvm.sqrt.f32(float) #0
8 declare <4 x float> @llvm.sqrt.v4f32(<4 x float>) #0
9 declare <8 x float> @llvm.sqrt.v8f32(<8 x float>) #0
12 define double @fd(double %d) #0 {
15 ; CHECK-NEXT: sqrtsd %xmm0, %xmm0
20 ; ESTIMATE-NEXT: vsqrtsd %xmm0, %xmm0, %xmm0
22 %call = tail call double @__sqrt_finite(double %d) #1
27 define float @ff(float %f) #0 {
30 ; CHECK-NEXT: sqrtss %xmm0, %xmm0
35 ; ESTIMATE-NEXT: vrsqrtss %xmm0, %xmm0, %xmm1
36 ; ESTIMATE-NEXT: vmulss {{.*}}(%rip), %xmm1, %xmm2
37 ; ESTIMATE-NEXT: vmulss %xmm1, %xmm1, %xmm1
38 ; ESTIMATE-NEXT: vmulss %xmm0, %xmm1, %xmm1
39 ; ESTIMATE-NEXT: vaddss {{.*}}(%rip), %xmm1, %xmm1
40 ; ESTIMATE-NEXT: vmulss %xmm2, %xmm1, %xmm1
41 ; ESTIMATE-NEXT: vmulss %xmm1, %xmm0, %xmm1
42 ; ESTIMATE-NEXT: vxorps %xmm2, %xmm2, %xmm2
43 ; ESTIMATE-NEXT: vcmpeqss %xmm2, %xmm0, %xmm0
44 ; ESTIMATE-NEXT: vandnps %xmm1, %xmm0, %xmm0
46 %call = tail call float @__sqrtf_finite(float %f) #1
51 define x86_fp80 @fld(x86_fp80 %ld) #0 {
54 ; CHECK-NEXT: fldt {{[0-9]+}}(%rsp)
58 ; ESTIMATE-LABEL: fld:
60 ; ESTIMATE-NEXT: fldt {{[0-9]+}}(%rsp)
61 ; ESTIMATE-NEXT: fsqrt
63 %call = tail call x86_fp80 @__sqrtl_finite(x86_fp80 %ld) #1
69 define float @reciprocal_square_root(float %x) #0 {
70 ; CHECK-LABEL: reciprocal_square_root:
72 ; CHECK-NEXT: sqrtss %xmm0, %xmm1
73 ; CHECK-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
74 ; CHECK-NEXT: divss %xmm1, %xmm0
77 ; ESTIMATE-LABEL: reciprocal_square_root:
79 ; ESTIMATE-NEXT: vrsqrtss %xmm0, %xmm0, %xmm1
80 ; ESTIMATE-NEXT: vmulss {{.*}}(%rip), %xmm1, %xmm2
81 ; ESTIMATE-NEXT: vmulss %xmm1, %xmm1, %xmm1
82 ; ESTIMATE-NEXT: vmulss %xmm0, %xmm1, %xmm0
83 ; ESTIMATE-NEXT: vaddss {{.*}}(%rip), %xmm0, %xmm0
84 ; ESTIMATE-NEXT: vmulss %xmm2, %xmm0, %xmm0
86 %sqrt = tail call float @llvm.sqrt.f32(float %x)
87 %div = fdiv fast float 1.0, %sqrt
91 define <4 x float> @reciprocal_square_root_v4f32(<4 x float> %x) #0 {
92 ; CHECK-LABEL: reciprocal_square_root_v4f32:
94 ; CHECK-NEXT: sqrtps %xmm0, %xmm1
95 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [1.000000e+00,1.000000e+00,1.000000e+00,1.000000e+00]
96 ; CHECK-NEXT: divps %xmm1, %xmm0
99 ; ESTIMATE-LABEL: reciprocal_square_root_v4f32:
101 ; ESTIMATE-NEXT: vrsqrtps %xmm0, %xmm1
102 ; ESTIMATE-NEXT: vmulps %xmm1, %xmm1, %xmm2
103 ; ESTIMATE-NEXT: vmulps %xmm0, %xmm2, %xmm0
104 ; ESTIMATE-NEXT: vaddps {{.*}}(%rip), %xmm0, %xmm0
105 ; ESTIMATE-NEXT: vmulps {{.*}}(%rip), %xmm1, %xmm1
106 ; ESTIMATE-NEXT: vmulps %xmm1, %xmm0, %xmm0
107 ; ESTIMATE-NEXT: retq
108 %sqrt = tail call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
109 %div = fdiv fast <4 x float> <float 1.0, float 1.0, float 1.0, float 1.0>, %sqrt
113 define <8 x float> @reciprocal_square_root_v8f32(<8 x float> %x) #0 {
114 ; CHECK-LABEL: reciprocal_square_root_v8f32:
116 ; CHECK-NEXT: sqrtps %xmm1, %xmm2
117 ; CHECK-NEXT: sqrtps %xmm0, %xmm3
118 ; CHECK-NEXT: movaps {{.*#+}} xmm1 = [1.000000e+00,1.000000e+00,1.000000e+00,1.000000e+00]
119 ; CHECK-NEXT: movaps %xmm1, %xmm0
120 ; CHECK-NEXT: divps %xmm3, %xmm0
121 ; CHECK-NEXT: divps %xmm2, %xmm1
124 ; ESTIMATE-LABEL: reciprocal_square_root_v8f32:
126 ; ESTIMATE-NEXT: vrsqrtps %ymm0, %ymm1
127 ; ESTIMATE-NEXT: vmulps %ymm1, %ymm1, %ymm2
128 ; ESTIMATE-NEXT: vmulps %ymm0, %ymm2, %ymm0
129 ; ESTIMATE-NEXT: vaddps {{.*}}(%rip), %ymm0, %ymm0
130 ; ESTIMATE-NEXT: vmulps {{.*}}(%rip), %ymm1, %ymm1
131 ; ESTIMATE-NEXT: vmulps %ymm1, %ymm0, %ymm0
132 ; ESTIMATE-NEXT: retq
133 %sqrt = tail call <8 x float> @llvm.sqrt.v8f32(<8 x float> %x)
134 %div = fdiv fast <8 x float> <float 1.0, float 1.0, float 1.0, float 1.0, float 1.0, float 1.0, float 1.0, float 1.0>, %sqrt
139 attributes #0 = { "unsafe-fp-math"="true" }
140 attributes #1 = { nounwind readnone }