1 ; RUN: llc < %s | FileCheck %s
2 target triple = "nvptx64-nvidia-cuda"
4 ; Checks that llvm intrinsics for math functions are correctly lowered to PTX.
6 declare float @llvm.ceil.f32(float) #0
7 declare double @llvm.ceil.f64(double) #0
8 declare float @llvm.floor.f32(float) #0
9 declare double @llvm.floor.f64(double) #0
10 declare float @llvm.round.f32(float) #0
11 declare double @llvm.round.f64(double) #0
12 declare float @llvm.nearbyint.f32(float) #0
13 declare double @llvm.nearbyint.f64(double) #0
14 declare float @llvm.rint.f32(float) #0
15 declare double @llvm.rint.f64(double) #0
16 declare float @llvm.trunc.f32(float) #0
17 declare double @llvm.trunc.f64(double) #0
18 declare float @llvm.fabs.f32(float) #0
19 declare double @llvm.fabs.f64(double) #0
20 declare float @llvm.minnum.f32(float, float) #0
21 declare double @llvm.minnum.f64(double, double) #0
22 declare float @llvm.maxnum.f32(float, float) #0
23 declare double @llvm.maxnum.f64(double, double) #0
24 declare float @llvm.fma.f32(float, float, float) #0
25 declare double @llvm.fma.f64(double, double, double) #0
29 ; CHECK-LABEL: ceil_float
30 define float @ceil_float(float %a) {
31 ; CHECK: cvt.rpi.f32.f32
32 %b = call float @llvm.ceil.f32(float %a)
36 ; CHECK-LABEL: ceil_float_ftz
37 define float @ceil_float_ftz(float %a) #1 {
38 ; CHECK: cvt.rpi.ftz.f32.f32
39 %b = call float @llvm.ceil.f32(float %a)
43 ; CHECK-LABEL: ceil_double
44 define double @ceil_double(double %a) {
45 ; CHECK: cvt.rpi.f64.f64
46 %b = call double @llvm.ceil.f64(double %a)
52 ; CHECK-LABEL: floor_float
53 define float @floor_float(float %a) {
54 ; CHECK: cvt.rmi.f32.f32
55 %b = call float @llvm.floor.f32(float %a)
59 ; CHECK-LABEL: floor_float_ftz
60 define float @floor_float_ftz(float %a) #1 {
61 ; CHECK: cvt.rmi.ftz.f32.f32
62 %b = call float @llvm.floor.f32(float %a)
66 ; CHECK-LABEL: floor_double
67 define double @floor_double(double %a) {
68 ; CHECK: cvt.rmi.f64.f64
69 %b = call double @llvm.floor.f64(double %a)
75 ; CHECK-LABEL: round_float
76 define float @round_float(float %a) {
77 ; check the use of sign mask and 0.5 to implement round
78 ; CHECK: and.b32 [[R1:%r[0-9]+]], {{.*}}, -2147483648;
79 ; CHECK: or.b32 {{.*}}, [[R1]], 1056964608;
80 %b = call float @llvm.round.f32(float %a)
84 ; CHECK-LABEL: round_float_ftz
85 define float @round_float_ftz(float %a) #1 {
86 ; check the use of sign mask and 0.5 to implement round
87 ; CHECK: and.b32 [[R1:%r[0-9]+]], {{.*}}, -2147483648;
88 ; CHECK: or.b32 {{.*}}, [[R1]], 1056964608;
89 %b = call float @llvm.round.f32(float %a)
93 ; CHECK-LABEL: round_double
94 define double @round_double(double %a) {
95 ; check the use of 0.5 to implement round
96 ; CHECK: setp.lt.f64 {{.*}}, [[R:%fd[0-9]+]], 0d3FE0000000000000;
97 ; CHECK: add.rn.f64 {{.*}}, [[R]], 0d3FE0000000000000;
98 %b = call double @llvm.round.f64(double %a)
102 ; ---- nearbyint ----
104 ; CHECK-LABEL: nearbyint_float
105 define float @nearbyint_float(float %a) {
106 ; CHECK: cvt.rni.f32.f32
107 %b = call float @llvm.nearbyint.f32(float %a)
111 ; CHECK-LABEL: nearbyint_float_ftz
112 define float @nearbyint_float_ftz(float %a) #1 {
113 ; CHECK: cvt.rni.ftz.f32.f32
114 %b = call float @llvm.nearbyint.f32(float %a)
118 ; CHECK-LABEL: nearbyint_double
119 define double @nearbyint_double(double %a) {
120 ; CHECK: cvt.rni.f64.f64
121 %b = call double @llvm.nearbyint.f64(double %a)
127 ; CHECK-LABEL: rint_float
128 define float @rint_float(float %a) {
129 ; CHECK: cvt.rni.f32.f32
130 %b = call float @llvm.rint.f32(float %a)
134 ; CHECK-LABEL: rint_float_ftz
135 define float @rint_float_ftz(float %a) #1 {
136 ; CHECK: cvt.rni.ftz.f32.f32
137 %b = call float @llvm.rint.f32(float %a)
141 ; CHECK-LABEL: rint_double
142 define double @rint_double(double %a) {
143 ; CHECK: cvt.rni.f64.f64
144 %b = call double @llvm.rint.f64(double %a)
150 ; CHECK-LABEL: trunc_float
151 define float @trunc_float(float %a) {
152 ; CHECK: cvt.rzi.f32.f32
153 %b = call float @llvm.trunc.f32(float %a)
157 ; CHECK-LABEL: trunc_float_ftz
158 define float @trunc_float_ftz(float %a) #1 {
159 ; CHECK: cvt.rzi.ftz.f32.f32
160 %b = call float @llvm.trunc.f32(float %a)
164 ; CHECK-LABEL: trunc_double
165 define double @trunc_double(double %a) {
166 ; CHECK: cvt.rzi.f64.f64
167 %b = call double @llvm.trunc.f64(double %a)
173 ; CHECK-LABEL: abs_float
174 define float @abs_float(float %a) {
176 %b = call float @llvm.fabs.f32(float %a)
180 ; CHECK-LABEL: abs_float_ftz
181 define float @abs_float_ftz(float %a) #1 {
183 %b = call float @llvm.fabs.f32(float %a)
187 ; CHECK-LABEL: abs_double
188 define double @abs_double(double %a) {
190 %b = call double @llvm.fabs.f64(double %a)
196 ; CHECK-LABEL: min_float
197 define float @min_float(float %a, float %b) {
199 %x = call float @llvm.minnum.f32(float %a, float %b)
203 ; CHECK-LABEL: min_imm1
204 define float @min_imm1(float %a) {
206 %x = call float @llvm.minnum.f32(float %a, float 0.0)
210 ; CHECK-LABEL: min_imm2
211 define float @min_imm2(float %a) {
213 %x = call float @llvm.minnum.f32(float 0.0, float %a)
217 ; CHECK-LABEL: min_float_ftz
218 define float @min_float_ftz(float %a, float %b) #1 {
220 %x = call float @llvm.minnum.f32(float %a, float %b)
224 ; CHECK-LABEL: min_double
225 define double @min_double(double %a, double %b) {
227 %x = call double @llvm.minnum.f64(double %a, double %b)
233 ; CHECK-LABEL: max_imm1
234 define float @max_imm1(float %a) {
236 %x = call float @llvm.maxnum.f32(float %a, float 0.0)
240 ; CHECK-LABEL: max_imm2
241 define float @max_imm2(float %a) {
243 %x = call float @llvm.maxnum.f32(float 0.0, float %a)
247 ; CHECK-LABEL: max_float
248 define float @max_float(float %a, float %b) {
250 %x = call float @llvm.maxnum.f32(float %a, float %b)
254 ; CHECK-LABEL: max_float_ftz
255 define float @max_float_ftz(float %a, float %b) #1 {
257 %x = call float @llvm.maxnum.f32(float %a, float %b)
261 ; CHECK-LABEL: max_double
262 define double @max_double(double %a, double %b) {
264 %x = call double @llvm.maxnum.f64(double %a, double %b)
270 ; CHECK-LABEL: @fma_float
271 define float @fma_float(float %a, float %b, float %c) {
273 %x = call float @llvm.fma.f32(float %a, float %b, float %c)
277 ; CHECK-LABEL: @fma_float_ftz
278 define float @fma_float_ftz(float %a, float %b, float %c) #1 {
279 ; CHECK: fma.rn.ftz.f32
280 %x = call float @llvm.fma.f32(float %a, float %b, float %c)
284 ; CHECK-LABEL: @fma_double
285 define double @fma_double(double %a, double %b, double %c) {
287 %x = call double @llvm.fma.f64(double %a, double %b, double %c)
291 attributes #0 = { nounwind readnone }
292 attributes #1 = { "nvptx-f32ftz" = "true" }