xref: /llvm-project/llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-fabs.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 @_Z4fabsf(float)
7declare <2 x float> @_Z4fabsDv2_f(<2 x float>)
8declare <3 x float> @_Z4fabsDv3_f(<3 x float>)
9declare <4 x float> @_Z4fabsDv4_f(<4 x float>)
10declare <8 x float> @_Z4fabsDv8_f(<8 x float>)
11declare <16 x float> @_Z4fabsDv16_f(<16 x float>)
12
13declare double @_Z4fabsd(double)
14declare <2 x double> @_Z4fabsDv2_d(<2 x double>)
15declare <3 x double> @_Z4fabsDv3_d(<3 x double>)
16declare <4 x double> @_Z4fabsDv4_d(<4 x double>)
17declare <8 x double> @_Z4fabsDv8_d(<8 x double>)
18declare <16 x double> @_Z4fabsDv16_d(<16 x double>)
19
20declare half @_Z4fabsDh(half)
21declare <2 x half> @_Z4fabsDv2_Dh(<2 x half>)
22declare <3 x half> @_Z4fabsDv3_Dh(<3 x half>)
23declare <4 x half> @_Z4fabsDv4_Dh(<4 x half>)
24declare <8 x half> @_Z4fabsDv8_Dh(<8 x half>)
25declare <16 x half> @_Z4fabsDv16_Dh(<16 x half>)
26
27define float @test_fabs_f32(float %arg) {
28; CHECK-LABEL: define float @test_fabs_f32
29; CHECK-SAME: (float [[ARG:%.*]]) {
30; CHECK-NEXT:    [[FABS:%.*]] = tail call float @llvm.fabs.f32(float [[ARG]])
31; CHECK-NEXT:    ret float [[FABS]]
32;
33  %fabs = tail call float @_Z4fabsf(float %arg)
34  ret float %fabs
35}
36
37define <2 x float> @test_fabs_v2f32(<2 x float> %arg) {
38; CHECK-LABEL: define <2 x float> @test_fabs_v2f32
39; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
40; CHECK-NEXT:    [[FABS:%.*]] = tail call <2 x float> @llvm.fabs.v2f32(<2 x float> [[ARG]])
41; CHECK-NEXT:    ret <2 x float> [[FABS]]
42;
43  %fabs = tail call <2 x float> @_Z4fabsDv2_f(<2 x float> %arg)
44  ret <2 x float> %fabs
45}
46
47define <3 x float> @test_fabs_v3f32(<3 x float> %arg) {
48; CHECK-LABEL: define <3 x float> @test_fabs_v3f32
49; CHECK-SAME: (<3 x float> [[ARG:%.*]]) {
50; CHECK-NEXT:    [[FABS:%.*]] = tail call <3 x float> @llvm.fabs.v3f32(<3 x float> [[ARG]])
51; CHECK-NEXT:    ret <3 x float> [[FABS]]
52;
53  %fabs = tail call <3 x float> @_Z4fabsDv3_f(<3 x float> %arg)
54  ret <3 x float> %fabs
55}
56
57define <4 x float> @test_fabs_v4f32(<4 x float> %arg) {
58; CHECK-LABEL: define <4 x float> @test_fabs_v4f32
59; CHECK-SAME: (<4 x float> [[ARG:%.*]]) {
60; CHECK-NEXT:    [[FABS:%.*]] = tail call <4 x float> @llvm.fabs.v4f32(<4 x float> [[ARG]])
61; CHECK-NEXT:    ret <4 x float> [[FABS]]
62;
63  %fabs = tail call <4 x float> @_Z4fabsDv4_f(<4 x float> %arg)
64  ret <4 x float> %fabs
65}
66
67define <8 x float> @test_fabs_v8f32(<8 x float> %arg) {
68; CHECK-LABEL: define <8 x float> @test_fabs_v8f32
69; CHECK-SAME: (<8 x float> [[ARG:%.*]]) {
70; CHECK-NEXT:    [[FABS:%.*]] = tail call <8 x float> @llvm.fabs.v8f32(<8 x float> [[ARG]])
71; CHECK-NEXT:    ret <8 x float> [[FABS]]
72;
73  %fabs = tail call <8 x float> @_Z4fabsDv8_f(<8 x float> %arg)
74  ret <8 x float> %fabs
75}
76
77define <16 x float> @test_fabs_v16f32(<16 x float> %arg) {
78; CHECK-LABEL: define <16 x float> @test_fabs_v16f32
79; CHECK-SAME: (<16 x float> [[ARG:%.*]]) {
80; CHECK-NEXT:    [[FABS:%.*]] = tail call <16 x float> @llvm.fabs.v16f32(<16 x float> [[ARG]])
81; CHECK-NEXT:    ret <16 x float> [[FABS]]
82;
83  %fabs = tail call <16 x float> @_Z4fabsDv16_f(<16 x float> %arg)
84  ret <16 x float> %fabs
85}
86
87define double @test_fabs_f64(double %arg) {
88; CHECK-LABEL: define double @test_fabs_f64
89; CHECK-SAME: (double [[ARG:%.*]]) {
90; CHECK-NEXT:    [[FABS:%.*]] = tail call double @llvm.fabs.f64(double [[ARG]])
91; CHECK-NEXT:    ret double [[FABS]]
92;
93  %fabs = tail call double @_Z4fabsd(double %arg)
94  ret double %fabs
95}
96
97define <2 x double> @test_fabs_v2f64(<2 x double> %arg) {
98; CHECK-LABEL: define <2 x double> @test_fabs_v2f64
99; CHECK-SAME: (<2 x double> [[ARG:%.*]]) {
100; CHECK-NEXT:    [[FABS:%.*]] = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> [[ARG]])
101; CHECK-NEXT:    ret <2 x double> [[FABS]]
102;
103  %fabs = tail call <2 x double> @_Z4fabsDv2_d(<2 x double> %arg)
104  ret <2 x double> %fabs
105}
106
107define <3 x double> @test_fabs_v3f64(<3 x double> %arg) {
108; CHECK-LABEL: define <3 x double> @test_fabs_v3f64
109; CHECK-SAME: (<3 x double> [[ARG:%.*]]) {
110; CHECK-NEXT:    [[FABS:%.*]] = tail call <3 x double> @llvm.fabs.v3f64(<3 x double> [[ARG]])
111; CHECK-NEXT:    ret <3 x double> [[FABS]]
112;
113  %fabs = tail call <3 x double> @_Z4fabsDv3_d(<3 x double> %arg)
114  ret <3 x double> %fabs
115}
116
117define <4 x double> @test_fabs_v4f64(<4 x double> %arg) {
118; CHECK-LABEL: define <4 x double> @test_fabs_v4f64
119; CHECK-SAME: (<4 x double> [[ARG:%.*]]) {
120; CHECK-NEXT:    [[FABS:%.*]] = tail call <4 x double> @llvm.fabs.v4f64(<4 x double> [[ARG]])
121; CHECK-NEXT:    ret <4 x double> [[FABS]]
122;
123  %fabs = tail call <4 x double> @_Z4fabsDv4_d(<4 x double> %arg)
124  ret <4 x double> %fabs
125}
126
127define <8 x double> @test_fabs_v8f64(<8 x double> %arg) {
128; CHECK-LABEL: define <8 x double> @test_fabs_v8f64
129; CHECK-SAME: (<8 x double> [[ARG:%.*]]) {
130; CHECK-NEXT:    [[FABS:%.*]] = tail call <8 x double> @llvm.fabs.v8f64(<8 x double> [[ARG]])
131; CHECK-NEXT:    ret <8 x double> [[FABS]]
132;
133  %fabs = tail call <8 x double> @_Z4fabsDv8_d(<8 x double> %arg)
134  ret <8 x double> %fabs
135}
136
137define <16 x double> @test_fabs_v16f64(<16 x double> %arg) {
138; CHECK-LABEL: define <16 x double> @test_fabs_v16f64
139; CHECK-SAME: (<16 x double> [[ARG:%.*]]) {
140; CHECK-NEXT:    [[FABS:%.*]] = tail call <16 x double> @llvm.fabs.v16f64(<16 x double> [[ARG]])
141; CHECK-NEXT:    ret <16 x double> [[FABS]]
142;
143  %fabs = tail call <16 x double> @_Z4fabsDv16_d(<16 x double> %arg)
144  ret <16 x double> %fabs
145}
146
147define half @test_fabs_f16(half %arg) {
148; CHECK-LABEL: define half @test_fabs_f16
149; CHECK-SAME: (half [[ARG:%.*]]) {
150; CHECK-NEXT:    [[FABS:%.*]] = tail call half @llvm.fabs.f16(half [[ARG]])
151; CHECK-NEXT:    ret half [[FABS]]
152;
153  %fabs = tail call half @_Z4fabsDh(half %arg)
154  ret half %fabs
155}
156
157define <2 x half> @test_fabs_v2f16(<2 x half> %arg) {
158; CHECK-LABEL: define <2 x half> @test_fabs_v2f16
159; CHECK-SAME: (<2 x half> [[ARG:%.*]]) {
160; CHECK-NEXT:    [[FABS:%.*]] = tail call <2 x half> @llvm.fabs.v2f16(<2 x half> [[ARG]])
161; CHECK-NEXT:    ret <2 x half> [[FABS]]
162;
163  %fabs = tail call <2 x half> @_Z4fabsDv2_Dh(<2 x half> %arg)
164  ret <2 x half> %fabs
165}
166
167define <3 x half> @test_fabs_v3f16(<3 x half> %arg) {
168; CHECK-LABEL: define <3 x half> @test_fabs_v3f16
169; CHECK-SAME: (<3 x half> [[ARG:%.*]]) {
170; CHECK-NEXT:    [[FABS:%.*]] = tail call <3 x half> @llvm.fabs.v3f16(<3 x half> [[ARG]])
171; CHECK-NEXT:    ret <3 x half> [[FABS]]
172;
173  %fabs = tail call <3 x half> @_Z4fabsDv3_Dh(<3 x half> %arg)
174  ret <3 x half> %fabs
175}
176
177define <4 x half> @test_fabs_v4f16(<4 x half> %arg) {
178; CHECK-LABEL: define <4 x half> @test_fabs_v4f16
179; CHECK-SAME: (<4 x half> [[ARG:%.*]]) {
180; CHECK-NEXT:    [[FABS:%.*]] = tail call <4 x half> @llvm.fabs.v4f16(<4 x half> [[ARG]])
181; CHECK-NEXT:    ret <4 x half> [[FABS]]
182;
183  %fabs = tail call <4 x half> @_Z4fabsDv4_Dh(<4 x half> %arg)
184  ret <4 x half> %fabs
185}
186
187define <8 x half> @test_fabs_v8f16(<8 x half> %arg) {
188; CHECK-LABEL: define <8 x half> @test_fabs_v8f16
189; CHECK-SAME: (<8 x half> [[ARG:%.*]]) {
190; CHECK-NEXT:    [[FABS:%.*]] = tail call <8 x half> @llvm.fabs.v8f16(<8 x half> [[ARG]])
191; CHECK-NEXT:    ret <8 x half> [[FABS]]
192;
193  %fabs = tail call <8 x half> @_Z4fabsDv8_Dh(<8 x half> %arg)
194  ret <8 x half> %fabs
195}
196
197define <16 x half> @test_fabs_v16f16(<16 x half> %arg) {
198; CHECK-LABEL: define <16 x half> @test_fabs_v16f16
199; CHECK-SAME: (<16 x half> [[ARG:%.*]]) {
200; CHECK-NEXT:    [[FABS:%.*]] = tail call <16 x half> @llvm.fabs.v16f16(<16 x half> [[ARG]])
201; CHECK-NEXT:    ret <16 x half> [[FABS]]
202;
203  %fabs = tail call <16 x half> @_Z4fabsDv16_Dh(<16 x half> %arg)
204  ret <16 x half> %fabs
205}
206
207define float @test_fabs_f32_nobuiltin_callsite(float %arg) {
208; CHECK-LABEL: define float @test_fabs_f32_nobuiltin_callsite
209; CHECK-SAME: (float [[ARG:%.*]]) {
210; CHECK-NEXT:    [[FABS:%.*]] = tail call float @_Z4fabsf(float [[ARG]]) #[[ATTR4:[0-9]+]]
211; CHECK-NEXT:    ret float [[FABS]]
212;
213  %fabs = tail call float @_Z4fabsf(float %arg) #0
214  ret float %fabs
215}
216
217define <2 x float> @test_fabs_v2f32_nobuiltin_callsite(<2 x float> %arg) {
218; CHECK-LABEL: define <2 x float> @test_fabs_v2f32_nobuiltin_callsite
219; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
220; CHECK-NEXT:    [[FABS:%.*]] = tail call <2 x float> @_Z4fabsDv2_f(<2 x float> [[ARG]]) #[[ATTR4]]
221; CHECK-NEXT:    ret <2 x float> [[FABS]]
222;
223  %fabs = tail call <2 x float> @_Z4fabsDv2_f(<2 x float> %arg) #0
224  ret <2 x float> %fabs
225}
226
227; "no-builtins" should be ignored
228define float @test_fabs_f32_nobuiltins(float %arg) #1 {
229; CHECK-LABEL: define float @test_fabs_f32_nobuiltins
230; CHECK-SAME: (float [[ARG:%.*]]) #[[ATTR0:[0-9]+]] {
231; CHECK-NEXT:    [[FABS:%.*]] = tail call float @_Z4fabsf(float [[ARG]]) #[[ATTR4]]
232; CHECK-NEXT:    ret float [[FABS]]
233;
234  %fabs = tail call float @_Z4fabsf(float %arg) #0
235  ret float %fabs
236}
237
238define <2 x float> @test_fabs_v2f32_nobuiltins(<2 x float> %arg) #1 {
239; CHECK-LABEL: define <2 x float> @test_fabs_v2f32_nobuiltins
240; CHECK-SAME: (<2 x float> [[ARG:%.*]]) #[[ATTR0]] {
241; CHECK-NEXT:    [[FABS:%.*]] = tail call <2 x float> @_Z4fabsDv2_f(<2 x float> [[ARG]]) #[[ATTR4]]
242; CHECK-NEXT:    ret <2 x float> [[FABS]]
243;
244  %fabs = tail call <2 x float> @_Z4fabsDv2_f(<2 x float> %arg) #0
245  ret <2 x float> %fabs
246}
247
248define float @test_fabs_f32_preserve_flags(float %arg) {
249; CHECK-LABEL: define float @test_fabs_f32_preserve_flags
250; CHECK-SAME: (float [[ARG:%.*]]) {
251; CHECK-NEXT:    [[FABS:%.*]] = tail call nnan ninf float @llvm.fabs.f32(float [[ARG]])
252; CHECK-NEXT:    ret float [[FABS]]
253;
254  %fabs = tail call nnan ninf float @_Z4fabsf(float %arg)
255  ret float %fabs
256}
257
258define <2 x float> @test_fabs_v2f32_preserve_flags(<2 x float> %arg) {
259; CHECK-LABEL: define <2 x float> @test_fabs_v2f32_preserve_flags
260; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
261; CHECK-NEXT:    [[FABS:%.*]] = tail call nnan nsz contract <2 x float> @llvm.fabs.v2f32(<2 x float> [[ARG]])
262; CHECK-NEXT:    ret <2 x float> [[FABS]]
263;
264  %fabs = tail call contract nsz nnan <2 x float> @_Z4fabsDv2_f(<2 x float> %arg)
265  ret <2 x float> %fabs
266}
267
268define float @test_fabs_f32_preserve_flags_md(float %arg) {
269; CHECK-LABEL: define float @test_fabs_f32_preserve_flags_md
270; CHECK-SAME: (float [[ARG:%.*]]) {
271; CHECK-NEXT:    [[FABS:%.*]] = tail call nnan ninf float @llvm.fabs.f32(float [[ARG]]), !foo !0
272; CHECK-NEXT:    ret float [[FABS]]
273;
274  %fabs = tail call nnan ninf float @_Z4fabsf(float %arg), !foo !0
275  ret float %fabs
276}
277
278define <2 x float> @test_fabs_v2f32_preserve_flags_md(<2 x float> %arg) {
279; CHECK-LABEL: define <2 x float> @test_fabs_v2f32_preserve_flags_md
280; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
281; CHECK-NEXT:    [[FABS:%.*]] = tail call nnan nsz contract <2 x float> @llvm.fabs.v2f32(<2 x float> [[ARG]]), !foo !0
282; CHECK-NEXT:    ret <2 x float> [[FABS]]
283;
284  %fabs = tail call contract nsz nnan <2 x float> @_Z4fabsDv2_f(<2 x float> %arg), !foo !0
285  ret <2 x float> %fabs
286}
287
288; Test the libm name, not a recognized opencl builtin.
289declare float @fabsf(float) #2
290declare double @fabs(double) #2
291
292define float @test_libm_fabs_f32(float %arg) {
293; CHECK-LABEL: define float @test_libm_fabs_f32
294; CHECK-SAME: (float [[ARG:%.*]]) {
295; CHECK-NEXT:    [[FABS:%.*]] = tail call float @fabsf(float [[ARG]])
296; CHECK-NEXT:    ret float [[FABS]]
297;
298  %fabs = tail call float @fabsf(float %arg)
299  ret float %fabs
300}
301
302define double @test_libm_fabs_f64(double %arg) {
303; CHECK-LABEL: define double @test_libm_fabs_f64
304; CHECK-SAME: (double [[ARG:%.*]]) {
305; CHECK-NEXT:    [[FABS:%.*]] = tail call double @fabs(double [[ARG]])
306; CHECK-NEXT:    ret double [[FABS]]
307;
308  %fabs = tail call double @fabs(double %arg)
309  ret double %fabs
310}
311
312define float @test_fabs_f32_strictfp(float %arg) #3 {
313; CHECK-LABEL: define float @test_fabs_f32_strictfp
314; CHECK-SAME: (float [[ARG:%.*]]) #[[ATTR2:[0-9]+]] {
315; CHECK-NEXT:    [[FABS:%.*]] = tail call nnan float @llvm.fabs.f32(float [[ARG]]) #[[ATTR2]]
316; CHECK-NEXT:    ret float [[FABS]]
317;
318  %fabs = tail call nnan float @_Z4fabsf(float %arg) #3
319  ret float %fabs
320}
321
322attributes #0 = { nobuiltin }
323attributes #1 = { "no-builtins" }
324attributes #2 = { nounwind memory(none) }
325attributes #3 = { strictfp }
326
327!0 = !{i32 1234}
328