xref: /llvm-project/llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-rint.ll (revision 32f9983c064557883223b585810eac3c6797d500)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-simplifylib %s | FileCheck %s
3
4target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
5
6declare float @_Z4rintf(float)
7declare <2 x float> @_Z4rintDv2_f(<2 x float>)
8declare <3 x float> @_Z4rintDv3_f(<3 x float>)
9declare <4 x float> @_Z4rintDv4_f(<4 x float>)
10declare <8 x float> @_Z4rintDv8_f(<8 x float>)
11declare <16 x float> @_Z4rintDv16_f(<16 x float>)
12
13declare double @_Z4rintd(double)
14declare <2 x double> @_Z4rintDv2_d(<2 x double>)
15declare <3 x double> @_Z4rintDv3_d(<3 x double>)
16declare <4 x double> @_Z4rintDv4_d(<4 x double>)
17declare <8 x double> @_Z4rintDv8_d(<8 x double>)
18declare <16 x double> @_Z4rintDv16_d(<16 x double>)
19
20declare half @_Z4rintDh(half)
21declare <2 x half> @_Z4rintDv2_Dh(<2 x half>)
22declare <3 x half> @_Z4rintDv3_Dh(<3 x half>)
23declare <4 x half> @_Z4rintDv4_Dh(<4 x half>)
24declare <8 x half> @_Z4rintDv8_Dh(<8 x half>)
25declare <16 x half> @_Z4rintDv16_Dh(<16 x half>)
26
27define float @test_rint_f32(float %arg) {
28; CHECK-LABEL: define float @test_rint_f32
29; CHECK-SAME: (float [[ARG:%.*]]) {
30; CHECK-NEXT:    [[RINT:%.*]] = tail call float @llvm.rint.f32(float [[ARG]])
31; CHECK-NEXT:    ret float [[RINT]]
32;
33  %rint = tail call float @_Z4rintf(float %arg)
34  ret float %rint
35}
36
37define <2 x float> @test_rint_v2f32(<2 x float> %arg) {
38; CHECK-LABEL: define <2 x float> @test_rint_v2f32
39; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
40; CHECK-NEXT:    [[RINT:%.*]] = tail call <2 x float> @llvm.rint.v2f32(<2 x float> [[ARG]])
41; CHECK-NEXT:    ret <2 x float> [[RINT]]
42;
43  %rint = tail call <2 x float> @_Z4rintDv2_f(<2 x float> %arg)
44  ret <2 x float> %rint
45}
46
47define <3 x float> @test_rint_v3f32(<3 x float> %arg) {
48; CHECK-LABEL: define <3 x float> @test_rint_v3f32
49; CHECK-SAME: (<3 x float> [[ARG:%.*]]) {
50; CHECK-NEXT:    [[RINT:%.*]] = tail call <3 x float> @llvm.rint.v3f32(<3 x float> [[ARG]])
51; CHECK-NEXT:    ret <3 x float> [[RINT]]
52;
53  %rint = tail call <3 x float> @_Z4rintDv3_f(<3 x float> %arg)
54  ret <3 x float> %rint
55}
56
57define <4 x float> @test_rint_v4f32(<4 x float> %arg) {
58; CHECK-LABEL: define <4 x float> @test_rint_v4f32
59; CHECK-SAME: (<4 x float> [[ARG:%.*]]) {
60; CHECK-NEXT:    [[RINT:%.*]] = tail call <4 x float> @llvm.rint.v4f32(<4 x float> [[ARG]])
61; CHECK-NEXT:    ret <4 x float> [[RINT]]
62;
63  %rint = tail call <4 x float> @_Z4rintDv4_f(<4 x float> %arg)
64  ret <4 x float> %rint
65}
66
67define <8 x float> @test_rint_v8f32(<8 x float> %arg) {
68; CHECK-LABEL: define <8 x float> @test_rint_v8f32
69; CHECK-SAME: (<8 x float> [[ARG:%.*]]) {
70; CHECK-NEXT:    [[RINT:%.*]] = tail call <8 x float> @llvm.rint.v8f32(<8 x float> [[ARG]])
71; CHECK-NEXT:    ret <8 x float> [[RINT]]
72;
73  %rint = tail call <8 x float> @_Z4rintDv8_f(<8 x float> %arg)
74  ret <8 x float> %rint
75}
76
77define <16 x float> @test_rint_v16f32(<16 x float> %arg) {
78; CHECK-LABEL: define <16 x float> @test_rint_v16f32
79; CHECK-SAME: (<16 x float> [[ARG:%.*]]) {
80; CHECK-NEXT:    [[RINT:%.*]] = tail call <16 x float> @llvm.rint.v16f32(<16 x float> [[ARG]])
81; CHECK-NEXT:    ret <16 x float> [[RINT]]
82;
83  %rint = tail call <16 x float> @_Z4rintDv16_f(<16 x float> %arg)
84  ret <16 x float> %rint
85}
86
87define double @test_rint_f64(double %arg) {
88; CHECK-LABEL: define double @test_rint_f64
89; CHECK-SAME: (double [[ARG:%.*]]) {
90; CHECK-NEXT:    [[RINT:%.*]] = tail call double @llvm.rint.f64(double [[ARG]])
91; CHECK-NEXT:    ret double [[RINT]]
92;
93  %rint = tail call double @_Z4rintd(double %arg)
94  ret double %rint
95}
96
97define <2 x double> @test_rint_v2f64(<2 x double> %arg) {
98; CHECK-LABEL: define <2 x double> @test_rint_v2f64
99; CHECK-SAME: (<2 x double> [[ARG:%.*]]) {
100; CHECK-NEXT:    [[RINT:%.*]] = tail call <2 x double> @llvm.rint.v2f64(<2 x double> [[ARG]])
101; CHECK-NEXT:    ret <2 x double> [[RINT]]
102;
103  %rint = tail call <2 x double> @_Z4rintDv2_d(<2 x double> %arg)
104  ret <2 x double> %rint
105}
106
107define <3 x double> @test_rint_v3f64(<3 x double> %arg) {
108; CHECK-LABEL: define <3 x double> @test_rint_v3f64
109; CHECK-SAME: (<3 x double> [[ARG:%.*]]) {
110; CHECK-NEXT:    [[RINT:%.*]] = tail call <3 x double> @llvm.rint.v3f64(<3 x double> [[ARG]])
111; CHECK-NEXT:    ret <3 x double> [[RINT]]
112;
113  %rint = tail call <3 x double> @_Z4rintDv3_d(<3 x double> %arg)
114  ret <3 x double> %rint
115}
116
117define <4 x double> @test_rint_v4f64(<4 x double> %arg) {
118; CHECK-LABEL: define <4 x double> @test_rint_v4f64
119; CHECK-SAME: (<4 x double> [[ARG:%.*]]) {
120; CHECK-NEXT:    [[RINT:%.*]] = tail call <4 x double> @llvm.rint.v4f64(<4 x double> [[ARG]])
121; CHECK-NEXT:    ret <4 x double> [[RINT]]
122;
123  %rint = tail call <4 x double> @_Z4rintDv4_d(<4 x double> %arg)
124  ret <4 x double> %rint
125}
126
127define <8 x double> @test_rint_v8f64(<8 x double> %arg) {
128; CHECK-LABEL: define <8 x double> @test_rint_v8f64
129; CHECK-SAME: (<8 x double> [[ARG:%.*]]) {
130; CHECK-NEXT:    [[RINT:%.*]] = tail call <8 x double> @llvm.rint.v8f64(<8 x double> [[ARG]])
131; CHECK-NEXT:    ret <8 x double> [[RINT]]
132;
133  %rint = tail call <8 x double> @_Z4rintDv8_d(<8 x double> %arg)
134  ret <8 x double> %rint
135}
136
137define <16 x double> @test_rint_v16f64(<16 x double> %arg) {
138; CHECK-LABEL: define <16 x double> @test_rint_v16f64
139; CHECK-SAME: (<16 x double> [[ARG:%.*]]) {
140; CHECK-NEXT:    [[RINT:%.*]] = tail call <16 x double> @llvm.rint.v16f64(<16 x double> [[ARG]])
141; CHECK-NEXT:    ret <16 x double> [[RINT]]
142;
143  %rint = tail call <16 x double> @_Z4rintDv16_d(<16 x double> %arg)
144  ret <16 x double> %rint
145}
146
147define half @test_rint_f16(half %arg) {
148; CHECK-LABEL: define half @test_rint_f16
149; CHECK-SAME: (half [[ARG:%.*]]) {
150; CHECK-NEXT:    [[RINT:%.*]] = tail call half @llvm.rint.f16(half [[ARG]])
151; CHECK-NEXT:    ret half [[RINT]]
152;
153  %rint = tail call half @_Z4rintDh(half %arg)
154  ret half %rint
155}
156
157define <2 x half> @test_rint_v2f16(<2 x half> %arg) {
158; CHECK-LABEL: define <2 x half> @test_rint_v2f16
159; CHECK-SAME: (<2 x half> [[ARG:%.*]]) {
160; CHECK-NEXT:    [[RINT:%.*]] = tail call <2 x half> @llvm.rint.v2f16(<2 x half> [[ARG]])
161; CHECK-NEXT:    ret <2 x half> [[RINT]]
162;
163  %rint = tail call <2 x half> @_Z4rintDv2_Dh(<2 x half> %arg)
164  ret <2 x half> %rint
165}
166
167define <3 x half> @test_rint_v3f16(<3 x half> %arg) {
168; CHECK-LABEL: define <3 x half> @test_rint_v3f16
169; CHECK-SAME: (<3 x half> [[ARG:%.*]]) {
170; CHECK-NEXT:    [[RINT:%.*]] = tail call <3 x half> @llvm.rint.v3f16(<3 x half> [[ARG]])
171; CHECK-NEXT:    ret <3 x half> [[RINT]]
172;
173  %rint = tail call <3 x half> @_Z4rintDv3_Dh(<3 x half> %arg)
174  ret <3 x half> %rint
175}
176
177define <4 x half> @test_rint_v4f16(<4 x half> %arg) {
178; CHECK-LABEL: define <4 x half> @test_rint_v4f16
179; CHECK-SAME: (<4 x half> [[ARG:%.*]]) {
180; CHECK-NEXT:    [[RINT:%.*]] = tail call <4 x half> @llvm.rint.v4f16(<4 x half> [[ARG]])
181; CHECK-NEXT:    ret <4 x half> [[RINT]]
182;
183  %rint = tail call <4 x half> @_Z4rintDv4_Dh(<4 x half> %arg)
184  ret <4 x half> %rint
185}
186
187define <8 x half> @test_rint_v8f16(<8 x half> %arg) {
188; CHECK-LABEL: define <8 x half> @test_rint_v8f16
189; CHECK-SAME: (<8 x half> [[ARG:%.*]]) {
190; CHECK-NEXT:    [[RINT:%.*]] = tail call <8 x half> @llvm.rint.v8f16(<8 x half> [[ARG]])
191; CHECK-NEXT:    ret <8 x half> [[RINT]]
192;
193  %rint = tail call <8 x half> @_Z4rintDv8_Dh(<8 x half> %arg)
194  ret <8 x half> %rint
195}
196
197define <16 x half> @test_rint_v16f16(<16 x half> %arg) {
198; CHECK-LABEL: define <16 x half> @test_rint_v16f16
199; CHECK-SAME: (<16 x half> [[ARG:%.*]]) {
200; CHECK-NEXT:    [[RINT:%.*]] = tail call <16 x half> @llvm.rint.v16f16(<16 x half> [[ARG]])
201; CHECK-NEXT:    ret <16 x half> [[RINT]]
202;
203  %rint = tail call <16 x half> @_Z4rintDv16_Dh(<16 x half> %arg)
204  ret <16 x half> %rint
205}
206
207define float @test_rint_f32_nobuiltin_callsite(float %arg) {
208; CHECK-LABEL: define float @test_rint_f32_nobuiltin_callsite
209; CHECK-SAME: (float [[ARG:%.*]]) {
210; CHECK-NEXT:    [[RINT:%.*]] = tail call float @_Z4rintf(float [[ARG]]) #[[ATTR4:[0-9]+]]
211; CHECK-NEXT:    ret float [[RINT]]
212;
213  %rint = tail call float @_Z4rintf(float %arg) #0
214  ret float %rint
215}
216
217define <2 x float> @test_rint_v2f32_nobuiltin_callsite(<2 x float> %arg) {
218; CHECK-LABEL: define <2 x float> @test_rint_v2f32_nobuiltin_callsite
219; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
220; CHECK-NEXT:    [[RINT:%.*]] = tail call <2 x float> @_Z4rintDv2_f(<2 x float> [[ARG]]) #[[ATTR4]]
221; CHECK-NEXT:    ret <2 x float> [[RINT]]
222;
223  %rint = tail call <2 x float> @_Z4rintDv2_f(<2 x float> %arg) #0
224  ret <2 x float> %rint
225}
226
227; "no-builtins" should be ignored
228define float @test_rint_f32_nobuiltins(float %arg) #1 {
229; CHECK-LABEL: define float @test_rint_f32_nobuiltins
230; CHECK-SAME: (float [[ARG:%.*]]) #[[ATTR0:[0-9]+]] {
231; CHECK-NEXT:    [[RINT:%.*]] = tail call float @_Z4rintf(float [[ARG]]) #[[ATTR4]]
232; CHECK-NEXT:    ret float [[RINT]]
233;
234  %rint = tail call float @_Z4rintf(float %arg) #0
235  ret float %rint
236}
237
238define <2 x float> @test_rint_v2f32_nobuiltins(<2 x float> %arg) #1 {
239; CHECK-LABEL: define <2 x float> @test_rint_v2f32_nobuiltins
240; CHECK-SAME: (<2 x float> [[ARG:%.*]]) #[[ATTR0]] {
241; CHECK-NEXT:    [[RINT:%.*]] = tail call <2 x float> @_Z4rintDv2_f(<2 x float> [[ARG]]) #[[ATTR4]]
242; CHECK-NEXT:    ret <2 x float> [[RINT]]
243;
244  %rint = tail call <2 x float> @_Z4rintDv2_f(<2 x float> %arg) #0
245  ret <2 x float> %rint
246}
247
248define float @test_rint_f32_preserve_flags(float %arg) {
249; CHECK-LABEL: define float @test_rint_f32_preserve_flags
250; CHECK-SAME: (float [[ARG:%.*]]) {
251; CHECK-NEXT:    [[RINT:%.*]] = tail call nnan ninf float @llvm.rint.f32(float [[ARG]])
252; CHECK-NEXT:    ret float [[RINT]]
253;
254  %rint = tail call nnan ninf float @_Z4rintf(float %arg)
255  ret float %rint
256}
257
258define <2 x float> @test_rint_v2f32_preserve_flags(<2 x float> %arg) {
259; CHECK-LABEL: define <2 x float> @test_rint_v2f32_preserve_flags
260; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
261; CHECK-NEXT:    [[RINT:%.*]] = tail call nnan nsz contract <2 x float> @llvm.rint.v2f32(<2 x float> [[ARG]])
262; CHECK-NEXT:    ret <2 x float> [[RINT]]
263;
264  %rint = tail call contract nsz nnan <2 x float> @_Z4rintDv2_f(<2 x float> %arg)
265  ret <2 x float> %rint
266}
267
268define float @test_rint_f32_preserve_flags_md(float %arg) {
269; CHECK-LABEL: define float @test_rint_f32_preserve_flags_md
270; CHECK-SAME: (float [[ARG:%.*]]) {
271; CHECK-NEXT:    [[RINT:%.*]] = tail call nnan ninf float @llvm.rint.f32(float [[ARG]]), !foo !0
272; CHECK-NEXT:    ret float [[RINT]]
273;
274  %rint = tail call nnan ninf float @_Z4rintf(float %arg), !foo !0
275  ret float %rint
276}
277
278define <2 x float> @test_rint_v2f32_preserve_flags_md(<2 x float> %arg) {
279; CHECK-LABEL: define <2 x float> @test_rint_v2f32_preserve_flags_md
280; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
281; CHECK-NEXT:    [[RINT:%.*]] = tail call nnan nsz contract <2 x float> @llvm.rint.v2f32(<2 x float> [[ARG]]), !foo !0
282; CHECK-NEXT:    ret <2 x float> [[RINT]]
283;
284  %rint = tail call contract nsz nnan <2 x float> @_Z4rintDv2_f(<2 x float> %arg), !foo !0
285  ret <2 x float> %rint
286}
287
288; Test the libm name, not a recognized opencl builtin.
289declare float @rintf(float) #2
290declare double @rint(double) #2
291
292define float @test_libm_rint_f32(float %arg) {
293; CHECK-LABEL: define float @test_libm_rint_f32
294; CHECK-SAME: (float [[ARG:%.*]]) {
295; CHECK-NEXT:    [[RINT:%.*]] = tail call float @rintf(float [[ARG]])
296; CHECK-NEXT:    ret float [[RINT]]
297;
298  %rint = tail call float @rintf(float %arg)
299  ret float %rint
300}
301
302define double @test_libm_rint_f64(double %arg) {
303; CHECK-LABEL: define double @test_libm_rint_f64
304; CHECK-SAME: (double [[ARG:%.*]]) {
305; CHECK-NEXT:    [[RINT:%.*]] = tail call double @rint(double [[ARG]])
306; CHECK-NEXT:    ret double [[RINT]]
307;
308  %rint = tail call double @rint(double %arg)
309  ret double %rint
310}
311
312define float @test_rint_f32_strictfp(float %arg) #3 {
313; CHECK-LABEL: define float @test_rint_f32_strictfp
314; CHECK-SAME: (float [[ARG:%.*]]) #[[ATTR2:[0-9]+]] {
315; CHECK-NEXT:    [[RINT:%.*]] = tail call nnan float @_Z4rintf(float [[ARG]]) #[[ATTR2]]
316; CHECK-NEXT:    ret float [[RINT]]
317;
318  %rint = tail call nnan float @_Z4rintf(float %arg) #3
319  ret float %rint
320}
321
322attributes #0 = { nobuiltin }
323attributes #1 = { "no-builtins" }
324attributes #2 = { nounwind memory(none) }
325attributes #3 = { strictfp }
326
327!0 = !{i32 1234}
328