1 ; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s
3 declare float @llvm.sqrt.f32(float)
4 declare double @llvm.sqrt.f64(double)
6 ; CHECK-LABEL: sqrt_div(
9 define float @sqrt_div(float %a, float %b) {
10 %t1 = tail call float @llvm.sqrt.f32(float %a)
11 %t2 = fdiv float %t1, %b
15 ; CHECK-LABEL: sqrt_div_fast(
17 ; CHECK: div.approx.f32
18 define float @sqrt_div_fast(float %a, float %b) #0 {
19 %t1 = tail call float @llvm.sqrt.f32(float %a)
20 %t2 = fdiv float %t1, %b
24 ; CHECK-LABEL: sqrt_div_fast_ninf(
25 ; CHECK: sqrt.approx.f32
26 ; CHECK: div.approx.f32
27 define float @sqrt_div_fast_ninf(float %a, float %b) #0 {
28 %t1 = tail call ninf afn float @llvm.sqrt.f32(float %a)
29 %t2 = fdiv float %t1, %b
33 ; CHECK-LABEL: sqrt_div_ftz(
34 ; CHECK: sqrt.rn.ftz.f32
35 ; CHECK: div.rn.ftz.f32
36 define float @sqrt_div_ftz(float %a, float %b) #1 {
37 %t1 = tail call float @llvm.sqrt.f32(float %a)
38 %t2 = fdiv float %t1, %b
42 ; CHECK-LABEL: sqrt_div_fast_ftz(
43 ; CHECK: sqrt.rn.ftz.f32
44 ; CHECK: div.approx.ftz.f32
45 define float @sqrt_div_fast_ftz(float %a, float %b) #0 #1 {
46 %t1 = tail call float @llvm.sqrt.f32(float %a)
47 %t2 = fdiv float %t1, %b
51 ; CHECK-LABEL: sqrt_div_fast_ftz_ninf(
52 ; CHECK: sqrt.approx.ftz.f32
53 ; CHECK: div.approx.ftz.f32
54 define float @sqrt_div_fast_ftz_ninf(float %a, float %b) #0 #1 {
55 %t1 = tail call ninf afn float @llvm.sqrt.f32(float %a)
56 %t2 = fdiv float %t1, %b
60 ; There are no fast-math or ftz versions of sqrt and div for f64. We use
61 ; reciprocal(rsqrt(x)) for sqrt(x), and emit a vanilla divide.
63 ; CHECK-LABEL: sqrt_div_fast_ftz_f64(
66 define double @sqrt_div_fast_ftz_f64(double %a, double %b) #0 #1 {
67 %t1 = tail call double @llvm.sqrt.f64(double %a)
68 %t2 = fdiv double %t1, %b
72 ; CHECK-LABEL: sqrt_div_fast_ftz_f64_ninf(
73 ; CHECK: rsqrt.approx.f64
74 ; CHECK: rcp.approx.ftz.f64
76 define double @sqrt_div_fast_ftz_f64_ninf(double %a, double %b) #0 #1 {
77 %t1 = tail call ninf afn double @llvm.sqrt.f64(double %a)
78 %t2 = fdiv double %t1, %b
83 ; CHECK-NOT: rsqrt.approx
85 ; CHECK-NOT: rsqrt.approx
86 define float @rsqrt(float %a) {
87 %b = tail call float @llvm.sqrt.f32(float %a)
88 %ret = fdiv float 1.0, %b
92 ; CHECK-LABEL: rsqrt_fast(
95 ; CHECK: rsqrt.approx.f32
98 define float @rsqrt_fast(float %a) #0 {
99 %b = tail call float @llvm.sqrt.f32(float %a)
100 %ret = fdiv float 1.0, %b
104 ; CHECK-LABEL: rsqrt_fast_ftz(
107 ; CHECK: rsqrt.approx.ftz.f32
110 define float @rsqrt_fast_ftz(float %a) #0 #1 {
111 %b = tail call float @llvm.sqrt.f32(float %a)
112 %ret = fdiv float 1.0, %b
118 define float @fadd(float %a, float %b) {
119 %t1 = fadd float %a, %b
123 ; CHECK-LABEL: fadd_ftz
124 ; CHECK: add.rn.ftz.f32
125 define float @fadd_ftz(float %a, float %b) #1 {
126 %t1 = fadd float %a, %b
130 declare float @llvm.sin.f32(float)
131 declare float @llvm.cos.f32(float)
133 ; CHECK-LABEL: fsin_approx
134 ; CHECK: sin.approx.f32
135 define float @fsin_approx(float %a) #0 {
136 %r = tail call float @llvm.sin.f32(float %a)
140 ; CHECK-LABEL: fcos_approx
141 ; CHECK: cos.approx.f32
142 define float @fcos_approx(float %a) #0 {
143 %r = tail call float @llvm.cos.f32(float %a)
147 ; CHECK-LABEL: repeated_div_recip_allowed
148 define float @repeated_div_recip_allowed(i1 %pred, float %a, float %b, float %divisor) {
154 %x = fdiv arcp float %a, %divisor
155 %y = fdiv arcp float %b, %divisor
156 %z = fmul float %x, %y
157 %w = select i1 %pred, float %z, float %y
161 ; CHECK-LABEL: repeated_div_recip_allowed_sel
162 define float @repeated_div_recip_allowed_sel(i1 %pred, float %a, float %b, float %divisor) {
165 %x = fdiv arcp float %a, %divisor
166 %y = fdiv arcp float %b, %divisor
167 %w = select i1 %pred, float %x, float %y
171 ; CHECK-LABEL: repeated_div_recip_allowed_ftz
172 define float @repeated_div_recip_allowed_ftz(i1 %pred, float %a, float %b, float %divisor) #1 {
173 ; CHECK: rcp.rn.ftz.f32
174 ; CHECK: mul.rn.ftz.f32
175 ; CHECK: mul.rn.ftz.f32
176 ; CHECK: mul.rn.ftz.f32
178 %x = fdiv arcp float %a, %divisor
179 %y = fdiv arcp float %b, %divisor
180 %z = fmul float %x, %y
181 %w = select i1 %pred, float %z, float %y
185 ; CHECK-LABEL: repeated_div_recip_allowed_ftz_sel
186 define float @repeated_div_recip_allowed_ftz_sel(i1 %pred, float %a, float %b, float %divisor) #1 {
188 ; CHECK: div.rn.ftz.f32
189 %x = fdiv arcp float %a, %divisor
190 %y = fdiv arcp float %b, %divisor
191 %w = select i1 %pred, float %x, float %y
195 ; CHECK-LABEL: repeated_div_fast
196 define float @repeated_div_fast(i1 %pred, float %a, float %b, float %divisor) #0 {
197 ; CHECK: rcp.approx.f32
202 %x = fdiv float %a, %divisor
203 %y = fdiv float %b, %divisor
204 %z = fmul float %x, %y
205 %w = select i1 %pred, float %z, float %y
209 ; CHECK-LABEL: repeated_div_fast_sel
210 define float @repeated_div_fast_sel(i1 %pred, float %a, float %b, float %divisor) #0 {
212 ; CHECK: div.approx.f32
213 %x = fdiv float %a, %divisor
214 %y = fdiv float %b, %divisor
215 %w = select i1 %pred, float %x, float %y
219 ; CHECK-LABEL: repeated_div_fast_ftz
220 define float @repeated_div_fast_ftz(i1 %pred, float %a, float %b, float %divisor) #0 #1 {
221 ; CHECK: rcp.approx.ftz.f32
226 %x = fdiv float %a, %divisor
227 %y = fdiv float %b, %divisor
228 %z = fmul float %x, %y
229 %w = select i1 %pred, float %z, float %y
233 ; CHECK-LABEL: repeated_div_fast_ftz_sel
234 define float @repeated_div_fast_ftz_sel(i1 %pred, float %a, float %b, float %divisor) #0 #1 {
236 ; CHECK: div.approx.ftz.f32
237 %x = fdiv float %a, %divisor
238 %y = fdiv float %b, %divisor
239 %w = select i1 %pred, float %x, float %y
243 attributes #0 = { "unsafe-fp-math" = "true" }
244 attributes #1 = { "denormal-fp-math-f32" = "preserve-sign" }