1 ; RUN: llc < %s -march=nvptx -mcpu=sm_20 -nvptx-prec-divf32=0 -nvptx-prec-sqrtf32=0 \
4 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"
6 declare float @llvm.sqrt.f32(float)
7 declare double @llvm.sqrt.f64(double)
9 ; -- reciprocal sqrt --
11 ; CHECK-LABEL: test_rsqrt32
12 define float @test_rsqrt32(float %a) #0 {
13 ; CHECK: rsqrt.approx.f32
14 %val = tail call float @llvm.sqrt.f32(float %a)
15 %ret = fdiv float 1.0, %val
19 ; CHECK-LABEL: test_rsqrt_ftz
20 define float @test_rsqrt_ftz(float %a) #0 #1 {
21 ; CHECK: rsqrt.approx.ftz.f32
22 %val = tail call float @llvm.sqrt.f32(float %a)
23 %ret = fdiv float 1.0, %val
27 ; CHECK-LABEL: test_rsqrt64
28 define double @test_rsqrt64(double %a) #0 {
29 ; CHECK: rsqrt.approx.f64
30 %val = tail call double @llvm.sqrt.f64(double %a)
31 %ret = fdiv double 1.0, %val
35 ; CHECK-LABEL: test_rsqrt64_ftz
36 define double @test_rsqrt64_ftz(double %a) #0 #1 {
37 ; There's no rsqrt.approx.ftz.f64 instruction; we just use the non-ftz version.
38 ; CHECK: rsqrt.approx.f64
39 %val = tail call double @llvm.sqrt.f64(double %a)
40 %ret = fdiv double 1.0, %val
46 ; CHECK-LABEL: test_sqrt32
47 define float @test_sqrt32(float %a) #0 {
49 %ret = tail call float @llvm.sqrt.f32(float %a)
53 ; CHECK-LABEL: test_sqrt32_ninf
54 define float @test_sqrt32_ninf(float %a) #0 {
55 ; CHECK: sqrt.approx.f32
56 %ret = tail call ninf afn float @llvm.sqrt.f32(float %a)
60 ; CHECK-LABEL: test_sqrt_ftz
61 define float @test_sqrt_ftz(float %a) #0 #1 {
62 ; CHECK: sqrt.rn.ftz.f32
63 %ret = tail call float @llvm.sqrt.f32(float %a)
67 ; CHECK-LABEL: test_sqrt_ftz_ninf
68 define float @test_sqrt_ftz_ninf(float %a) #0 #1 {
69 ; CHECK: sqrt.approx.ftz.f32
70 %ret = tail call ninf afn float @llvm.sqrt.f32(float %a)
74 ; CHECK-LABEL: test_sqrt64
75 define double @test_sqrt64(double %a) #0 {
77 %ret = tail call double @llvm.sqrt.f64(double %a)
81 ; CHECK-LABEL: test_sqrt64_ninf
82 define double @test_sqrt64_ninf(double %a) #0 {
83 ; There's no sqrt.approx.f64 instruction; we emit
84 ; reciprocal(rsqrt.approx.f64(x)). There's no non-ftz approximate reciprocal,
85 ; so we just use the ftz version.
86 ; CHECK: rsqrt.approx.f64
87 ; CHECK: rcp.approx.ftz.f64
88 %ret = tail call ninf afn double @llvm.sqrt.f64(double %a)
92 ; CHECK-LABEL: test_sqrt64_ftz
93 define double @test_sqrt64_ftz(double %a) #0 #1 {
95 %ret = tail call double @llvm.sqrt.f64(double %a)
99 ; CHECK-LABEL: test_sqrt64_ftz_ninf
100 define double @test_sqrt64_ftz_ninf(double %a) #0 #1 {
101 ; There's no sqrt.approx.ftz.f64 instruction; we just use the non-ftz version.
102 ; CHECK: rsqrt.approx.f64
103 ; CHECK: rcp.approx.ftz.f64
104 %ret = tail call ninf afn double @llvm.sqrt.f64(double %a)
108 ; -- refined sqrt and rsqrt --
110 ; The sqrt and rsqrt refinement algorithms both emit an rsqrt.approx, followed
113 ; CHECK-LABEL: test_rsqrt32_refined
114 define float @test_rsqrt32_refined(float %a) #0 #2 {
115 ; CHECK: rsqrt.approx.f32
116 %val = tail call float @llvm.sqrt.f32(float %a)
117 %ret = fdiv float 1.0, %val
121 ; CHECK-LABEL: test_sqrt32_refined
122 define float @test_sqrt32_refined(float %a) #0 #2 {
124 %ret = tail call float @llvm.sqrt.f32(float %a)
128 ; CHECK-LABEL: test_sqrt32_refined_ninf
129 define float @test_sqrt32_refined_ninf(float %a) #0 #2 {
130 ; CHECK: rsqrt.approx.f32
131 %ret = tail call ninf afn float @llvm.sqrt.f32(float %a)
135 ; CHECK-LABEL: test_rsqrt64_refined
136 define double @test_rsqrt64_refined(double %a) #0 #2 {
137 ; CHECK: rsqrt.approx.f64
138 %val = tail call double @llvm.sqrt.f64(double %a)
139 %ret = fdiv double 1.0, %val
143 ; CHECK-LABEL: test_sqrt64_refined
144 define double @test_sqrt64_refined(double %a) #0 #2 {
146 %ret = tail call double @llvm.sqrt.f64(double %a)
150 ; CHECK-LABEL: test_sqrt64_refined_ninf
151 define double @test_sqrt64_refined_ninf(double %a) #0 #2 {
152 ; CHECK: rsqrt.approx.f64
153 %ret = tail call ninf afn double @llvm.sqrt.f64(double %a)
157 ; -- refined sqrt and rsqrt with ftz enabled --
159 ; CHECK-LABEL: test_rsqrt32_refined_ftz
160 define float @test_rsqrt32_refined_ftz(float %a) #0 #1 #2 {
161 ; CHECK: rsqrt.approx.ftz.f32
162 %val = tail call float @llvm.sqrt.f32(float %a)
163 %ret = fdiv float 1.0, %val
167 ; CHECK-LABEL: test_sqrt32_refined_ftz
168 define float @test_sqrt32_refined_ftz(float %a) #0 #1 #2 {
169 ; CHECK: sqrt.rn.ftz.f32
170 %ret = tail call float @llvm.sqrt.f32(float %a)
174 ; CHECK-LABEL: test_sqrt32_refined_ftz_ninf
175 define float @test_sqrt32_refined_ftz_ninf(float %a) #0 #1 #2 {
176 ; CHECK: rsqrt.approx.ftz.f32
177 %ret = tail call ninf afn float @llvm.sqrt.f32(float %a)
181 ; CHECK-LABEL: test_rsqrt64_refined_ftz
182 define double @test_rsqrt64_refined_ftz(double %a) #0 #1 #2 {
183 ; There's no rsqrt.approx.ftz.f64, so we just use the non-ftz version.
184 ; CHECK: rsqrt.approx.f64
185 %val = tail call double @llvm.sqrt.f64(double %a)
186 %ret = fdiv double 1.0, %val
190 ; CHECK-LABEL: test_sqrt64_refined_ftz
191 define double @test_sqrt64_refined_ftz(double %a) #0 #1 #2 {
193 %ret = tail call double @llvm.sqrt.f64(double %a)
197 ; CHECK-LABEL: test_sqrt64_refined_ftz_ninf
198 define double @test_sqrt64_refined_ftz_ninf(double %a) #0 #1 #2 {
199 ; CHECK: rsqrt.approx.f64
200 %ret = tail call ninf afn double @llvm.sqrt.f64(double %a)
204 attributes #0 = { "unsafe-fp-math" = "true" }
205 attributes #1 = { "denormal-fp-math-f32" = "preserve-sign,preserve-sign" }
206 attributes #2 = { "reciprocal-estimates" = "rsqrtf:1,rsqrtd:1,sqrtf:1,sqrtd:1" }