1; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=sse2 | FileCheck %s 2; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=avx,use-sqrt-est | FileCheck %s --check-prefix=ESTIMATE 3 4declare double @__sqrt_finite(double) #0 5declare float @__sqrtf_finite(float) #0 6declare x86_fp80 @__sqrtl_finite(x86_fp80) #0 7declare float @llvm.sqrt.f32(float) #0 8declare <4 x float> @llvm.sqrt.v4f32(<4 x float>) #0 9declare <8 x float> @llvm.sqrt.v8f32(<8 x float>) #0 10 11 12define double @fd(double %d) #0 { 13; CHECK-LABEL: fd: 14; CHECK: # BB#0: 15; CHECK-NEXT: sqrtsd %xmm0, %xmm0 16; CHECK-NEXT: retq 17; 18; ESTIMATE-LABEL: fd: 19; ESTIMATE: # BB#0: 20; ESTIMATE-NEXT: vsqrtsd %xmm0, %xmm0, %xmm0 21; ESTIMATE-NEXT: retq 22 %call = tail call double @__sqrt_finite(double %d) #1 23 ret double %call 24} 25 26 27define float @ff(float %f) #0 { 28; CHECK-LABEL: ff: 29; CHECK: # BB#0: 30; CHECK-NEXT: sqrtss %xmm0, %xmm0 31; CHECK-NEXT: retq 32; 33; ESTIMATE-LABEL: ff: 34; ESTIMATE: # BB#0: 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 45; ESTIMATE-NEXT: retq 46 %call = tail call float @__sqrtf_finite(float %f) #1 47 ret float %call 48} 49 50 51define x86_fp80 @fld(x86_fp80 %ld) #0 { 52; CHECK-LABEL: fld: 53; CHECK: # BB#0: 54; CHECK-NEXT: fldt {{[0-9]+}}(%rsp) 55; CHECK-NEXT: fsqrt 56; CHECK-NEXT: retq 57; 58; ESTIMATE-LABEL: fld: 59; ESTIMATE: # BB#0: 60; ESTIMATE-NEXT: fldt {{[0-9]+}}(%rsp) 61; ESTIMATE-NEXT: fsqrt 62; ESTIMATE-NEXT: retq 63 %call = tail call x86_fp80 @__sqrtl_finite(x86_fp80 %ld) #1 64 ret x86_fp80 %call 65} 66 67 68 69define float @reciprocal_square_root(float %x) #0 { 70; CHECK-LABEL: reciprocal_square_root: 71; CHECK: # BB#0: 72; CHECK-NEXT: sqrtss %xmm0, %xmm1 73; CHECK-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero 74; CHECK-NEXT: divss %xmm1, %xmm0 75; CHECK-NEXT: retq 76; 77; ESTIMATE-LABEL: reciprocal_square_root: 78; ESTIMATE: # BB#0: 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 85; ESTIMATE-NEXT: retq 86 %sqrt = tail call float @llvm.sqrt.f32(float %x) 87 %div = fdiv fast float 1.0, %sqrt 88 ret float %div 89} 90 91define <4 x float> @reciprocal_square_root_v4f32(<4 x float> %x) #0 { 92; CHECK-LABEL: reciprocal_square_root_v4f32: 93; CHECK: # BB#0: 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 97; CHECK-NEXT: retq 98; 99; ESTIMATE-LABEL: reciprocal_square_root_v4f32: 100; ESTIMATE: # BB#0: 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 110 ret <4 x float> %div 111} 112 113define <8 x float> @reciprocal_square_root_v8f32(<8 x float> %x) #0 { 114; CHECK-LABEL: reciprocal_square_root_v8f32: 115; CHECK: # BB#0: 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 122; CHECK-NEXT: retq 123; 124; ESTIMATE-LABEL: reciprocal_square_root_v8f32: 125; ESTIMATE: # BB#0: 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 135 ret <8 x float> %div 136} 137 138 139attributes #0 = { "unsafe-fp-math"="true" } 140attributes #1 = { nounwind readnone } 141 142