xref: /llvm-project/llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-ldexp.ll (revision b446c208a5f0e2ad7193cc23e70642d207db4d13)
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 @_Z5ldexpfi(float, i32)
7declare <2 x float> @_Z5ldexpDv2_fDv2_i(<2 x float>, <2 x i32>)
8declare <3 x float> @_Z5ldexpDv3_fDv3_i(<3 x float>, <3 x i32>)
9declare <4 x float> @_Z5ldexpDv4_fDv4_i(<4 x float>, <4 x i32>)
10declare <8 x float> @_Z5ldexpDv8_fDv8_i(<8 x float>, <8 x i32>)
11declare <16 x float> @_Z5ldexpDv16_fDv16_i(<16 x float>, <16 x i32>)
12declare double @_Z5ldexpdi(double, i32)
13declare <2 x double> @_Z5ldexpDv2_dDv2_i(<2 x double>, <2 x i32>)
14declare <3 x double> @_Z5ldexpDv3_dDv3_i(<3 x double>, <3 x i32>)
15declare <4 x double> @_Z5ldexpDv4_dDv4_i(<4 x double>, <4 x i32>)
16declare <8 x double> @_Z5ldexpDv8_dDv8_i(<8 x double>, <8 x i32>)
17declare <16 x double> @_Z5ldexpDv16_dDv16_i(<16 x double>, <16 x i32>)
18declare half @_Z5ldexpDhi(half, i32)
19declare <2 x half> @_Z5ldexpDv2_DhDv2_i(<2 x half>, <2 x i32>)
20declare <3 x half> @_Z5ldexpDv3_DhDv3_i(<3 x half>, <3 x i32>)
21declare <4 x half> @_Z5ldexpDv4_DhDv4_i(<4 x half>, <4 x i32>)
22declare <8 x half> @_Z5ldexpDv8_DhDv8_i(<8 x half>, <8 x i32>)
23declare <16 x half> @_Z5ldexpDv16_DhDv16_i(<16 x half>, <16 x i32>)
24
25define float @test_ldexp_f32(float %x, i32 %y) {
26; CHECK-LABEL: define float @test_ldexp_f32
27; CHECK-SAME: (float [[X:%.*]], i32 [[Y:%.*]]) {
28; CHECK-NEXT:    [[LDEXP:%.*]] = tail call float @llvm.ldexp.f32.i32(float [[X]], i32 [[Y]])
29; CHECK-NEXT:    ret float [[LDEXP]]
30;
31  %ldexp = tail call float @_Z5ldexpfi(float %x, i32 %y)
32  ret float %ldexp
33}
34
35define float @test_ldexp_f32_fast(float %x, i32 %y) {
36; CHECK-LABEL: define float @test_ldexp_f32_fast
37; CHECK-SAME: (float [[X:%.*]], i32 [[Y:%.*]]) {
38; CHECK-NEXT:    [[LDEXP:%.*]] = tail call fast float @llvm.ldexp.f32.i32(float [[X]], i32 [[Y]])
39; CHECK-NEXT:    ret float [[LDEXP]]
40;
41  %ldexp = tail call fast float @_Z5ldexpfi(float %x, i32 %y)
42  ret float %ldexp
43}
44
45define <2 x float> @test_ldexp_v2f32(<2 x float> %x, <2 x i32> %y) {
46; CHECK-LABEL: define <2 x float> @test_ldexp_v2f32
47; CHECK-SAME: (<2 x float> [[X:%.*]], <2 x i32> [[Y:%.*]]) {
48; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <2 x float> @llvm.ldexp.v2f32.v2i32(<2 x float> [[X]], <2 x i32> [[Y]])
49; CHECK-NEXT:    ret <2 x float> [[LDEXP]]
50;
51  %ldexp = tail call <2 x float> @_Z5ldexpDv2_fDv2_i(<2 x float> %x, <2 x i32> %y)
52  ret <2 x float> %ldexp
53}
54
55define <3 x float> @test_ldexp_v3f32(<3 x float> %x, <3 x i32> %y) {
56; CHECK-LABEL: define <3 x float> @test_ldexp_v3f32
57; CHECK-SAME: (<3 x float> [[X:%.*]], <3 x i32> [[Y:%.*]]) {
58; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <3 x float> @llvm.ldexp.v3f32.v3i32(<3 x float> [[X]], <3 x i32> [[Y]])
59; CHECK-NEXT:    ret <3 x float> [[LDEXP]]
60;
61  %ldexp = tail call <3 x float> @_Z5ldexpDv3_fDv3_i(<3 x float> %x, <3 x i32> %y)
62  ret <3 x float> %ldexp
63}
64
65define <4 x float> @test_ldexp_v4f32(<4 x float> %x, <4 x i32> %y) {
66; CHECK-LABEL: define <4 x float> @test_ldexp_v4f32
67; CHECK-SAME: (<4 x float> [[X:%.*]], <4 x i32> [[Y:%.*]]) {
68; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <4 x float> @llvm.ldexp.v4f32.v4i32(<4 x float> [[X]], <4 x i32> [[Y]])
69; CHECK-NEXT:    ret <4 x float> [[LDEXP]]
70;
71  %ldexp = tail call <4 x float> @_Z5ldexpDv4_fDv4_i(<4 x float> %x, <4 x i32> %y)
72  ret <4 x float> %ldexp
73}
74
75define <8 x float> @test_ldexp_v8f32(<8 x float> %x, <8 x i32> %y) {
76; CHECK-LABEL: define <8 x float> @test_ldexp_v8f32
77; CHECK-SAME: (<8 x float> [[X:%.*]], <8 x i32> [[Y:%.*]]) {
78; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <8 x float> @llvm.ldexp.v8f32.v8i32(<8 x float> [[X]], <8 x i32> [[Y]])
79; CHECK-NEXT:    ret <8 x float> [[LDEXP]]
80;
81  %ldexp = tail call <8 x float> @_Z5ldexpDv8_fDv8_i(<8 x float> %x, <8 x i32> %y)
82  ret <8 x float> %ldexp
83}
84
85define <16 x float> @test_ldexp_v16f32(<16 x float> %x, <16 x i32> %y) {
86; CHECK-LABEL: define <16 x float> @test_ldexp_v16f32
87; CHECK-SAME: (<16 x float> [[X:%.*]], <16 x i32> [[Y:%.*]]) {
88; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <16 x float> @llvm.ldexp.v16f32.v16i32(<16 x float> [[X]], <16 x i32> [[Y]])
89; CHECK-NEXT:    ret <16 x float> [[LDEXP]]
90;
91  %ldexp = tail call <16 x float> @_Z5ldexpDv16_fDv16_i(<16 x float> %x, <16 x i32> %y)
92  ret <16 x float> %ldexp
93}
94
95define double @test_ldexp_f64(double %x, i32 %y) {
96; CHECK-LABEL: define double @test_ldexp_f64
97; CHECK-SAME: (double [[X:%.*]], i32 [[Y:%.*]]) {
98; CHECK-NEXT:    [[LDEXP:%.*]] = tail call double @llvm.ldexp.f64.i32(double [[X]], i32 [[Y]])
99; CHECK-NEXT:    ret double [[LDEXP]]
100;
101  %ldexp = tail call double @_Z5ldexpdi(double %x, i32 %y)
102  ret double %ldexp
103}
104
105define <2 x double> @test_ldexp_v2f64(<2 x double> %x, <2 x i32> %y) {
106; CHECK-LABEL: define <2 x double> @test_ldexp_v2f64
107; CHECK-SAME: (<2 x double> [[X:%.*]], <2 x i32> [[Y:%.*]]) {
108; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <2 x double> @llvm.ldexp.v2f64.v2i32(<2 x double> [[X]], <2 x i32> [[Y]])
109; CHECK-NEXT:    ret <2 x double> [[LDEXP]]
110;
111  %ldexp = tail call <2 x double> @_Z5ldexpDv2_dDv2_i(<2 x double> %x, <2 x i32> %y)
112  ret <2 x double> %ldexp
113}
114
115define <3 x double> @test_ldexp_v3f64(<3 x double> %x, <3 x i32> %y) {
116; CHECK-LABEL: define <3 x double> @test_ldexp_v3f64
117; CHECK-SAME: (<3 x double> [[X:%.*]], <3 x i32> [[Y:%.*]]) {
118; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <3 x double> @llvm.ldexp.v3f64.v3i32(<3 x double> [[X]], <3 x i32> [[Y]])
119; CHECK-NEXT:    ret <3 x double> [[LDEXP]]
120;
121  %ldexp = tail call <3 x double> @_Z5ldexpDv3_dDv3_i(<3 x double> %x, <3 x i32> %y)
122  ret <3 x double> %ldexp
123}
124
125define <4 x double> @test_ldexp_v4f64(<4 x double> %x, <4 x i32> %y) {
126; CHECK-LABEL: define <4 x double> @test_ldexp_v4f64
127; CHECK-SAME: (<4 x double> [[X:%.*]], <4 x i32> [[Y:%.*]]) {
128; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <4 x double> @llvm.ldexp.v4f64.v4i32(<4 x double> [[X]], <4 x i32> [[Y]])
129; CHECK-NEXT:    ret <4 x double> [[LDEXP]]
130;
131  %ldexp = tail call <4 x double> @_Z5ldexpDv4_dDv4_i(<4 x double> %x, <4 x i32> %y)
132  ret <4 x double> %ldexp
133}
134
135define <8 x double> @test_ldexp_v8f64(<8 x double> %x, <8 x i32> %y) {
136; CHECK-LABEL: define <8 x double> @test_ldexp_v8f64
137; CHECK-SAME: (<8 x double> [[X:%.*]], <8 x i32> [[Y:%.*]]) {
138; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <8 x double> @llvm.ldexp.v8f64.v8i32(<8 x double> [[X]], <8 x i32> [[Y]])
139; CHECK-NEXT:    ret <8 x double> [[LDEXP]]
140;
141  %ldexp = tail call <8 x double> @_Z5ldexpDv8_dDv8_i(<8 x double> %x, <8 x i32> %y)
142  ret <8 x double> %ldexp
143}
144
145define <16 x double> @test_ldexp_v16f64(<16 x double> %x, <16 x i32> %y) {
146; CHECK-LABEL: define <16 x double> @test_ldexp_v16f64
147; CHECK-SAME: (<16 x double> [[X:%.*]], <16 x i32> [[Y:%.*]]) {
148; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <16 x double> @llvm.ldexp.v16f64.v16i32(<16 x double> [[X]], <16 x i32> [[Y]])
149; CHECK-NEXT:    ret <16 x double> [[LDEXP]]
150;
151  %ldexp = tail call <16 x double> @_Z5ldexpDv16_dDv16_i(<16 x double> %x, <16 x i32> %y)
152  ret <16 x double> %ldexp
153}
154
155define half @test_ldexp_f16(half %x, i32 %y) {
156; CHECK-LABEL: define half @test_ldexp_f16
157; CHECK-SAME: (half [[X:%.*]], i32 [[Y:%.*]]) {
158; CHECK-NEXT:    [[LDEXP:%.*]] = tail call half @llvm.ldexp.f16.i32(half [[X]], i32 [[Y]])
159; CHECK-NEXT:    ret half [[LDEXP]]
160;
161  %ldexp = tail call half @_Z5ldexpDhi(half %x, i32 %y)
162  ret half %ldexp
163}
164
165define <2 x half> @test_ldexp_v2f16(<2 x half> %x, <2 x i32> %y) {
166; CHECK-LABEL: define <2 x half> @test_ldexp_v2f16
167; CHECK-SAME: (<2 x half> [[X:%.*]], <2 x i32> [[Y:%.*]]) {
168; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <2 x half> @llvm.ldexp.v2f16.v2i32(<2 x half> [[X]], <2 x i32> [[Y]])
169; CHECK-NEXT:    ret <2 x half> [[LDEXP]]
170;
171  %ldexp = tail call <2 x half> @_Z5ldexpDv2_DhDv2_i(<2 x half> %x, <2 x i32> %y)
172  ret <2 x half> %ldexp
173}
174
175define <3 x half> @test_ldexp_v3f16(<3 x half> %x, <3 x i32> %y) {
176; CHECK-LABEL: define <3 x half> @test_ldexp_v3f16
177; CHECK-SAME: (<3 x half> [[X:%.*]], <3 x i32> [[Y:%.*]]) {
178; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <3 x half> @llvm.ldexp.v3f16.v3i32(<3 x half> [[X]], <3 x i32> [[Y]])
179; CHECK-NEXT:    ret <3 x half> [[LDEXP]]
180;
181  %ldexp = tail call <3 x half> @_Z5ldexpDv3_DhDv3_i(<3 x half> %x, <3 x i32> %y)
182  ret <3 x half> %ldexp
183}
184
185define <4 x half> @test_ldexp_v4f16(<4 x half> %x, <4 x i32> %y) {
186; CHECK-LABEL: define <4 x half> @test_ldexp_v4f16
187; CHECK-SAME: (<4 x half> [[X:%.*]], <4 x i32> [[Y:%.*]]) {
188; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <4 x half> @llvm.ldexp.v4f16.v4i32(<4 x half> [[X]], <4 x i32> [[Y]])
189; CHECK-NEXT:    ret <4 x half> [[LDEXP]]
190;
191  %ldexp = tail call <4 x half> @_Z5ldexpDv4_DhDv4_i(<4 x half> %x, <4 x i32> %y)
192  ret <4 x half> %ldexp
193}
194
195define <8 x half> @test_ldexp_v8f16(<8 x half> %x, <8 x i32> %y) {
196; CHECK-LABEL: define <8 x half> @test_ldexp_v8f16
197; CHECK-SAME: (<8 x half> [[X:%.*]], <8 x i32> [[Y:%.*]]) {
198; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <8 x half> @llvm.ldexp.v8f16.v8i32(<8 x half> [[X]], <8 x i32> [[Y]])
199; CHECK-NEXT:    ret <8 x half> [[LDEXP]]
200;
201  %ldexp = tail call <8 x half> @_Z5ldexpDv8_DhDv8_i(<8 x half> %x, <8 x i32> %y)
202  ret <8 x half> %ldexp
203}
204
205define <16 x half> @test_ldexp_v16f16(<16 x half> %x, <16 x i32> %y) {
206; CHECK-LABEL: define <16 x half> @test_ldexp_v16f16
207; CHECK-SAME: (<16 x half> [[X:%.*]], <16 x i32> [[Y:%.*]]) {
208; CHECK-NEXT:    [[LDEXP:%.*]] = tail call <16 x half> @llvm.ldexp.v16f16.v16i32(<16 x half> [[X]], <16 x i32> [[Y]])
209; CHECK-NEXT:    ret <16 x half> [[LDEXP]]
210;
211  %ldexp = tail call <16 x half> @_Z5ldexpDv16_DhDv16_i(<16 x half> %x, <16 x i32> %y)
212  ret <16 x half> %ldexp
213}
214
215define float @test_ldexp_f32_minsize(float %x, i32 %y) #3 {
216; CHECK-LABEL: define float @test_ldexp_f32_minsize
217; CHECK-SAME: (float [[X:%.*]], i32 [[Y:%.*]]) #[[ATTR0:[0-9]+]] {
218; CHECK-NEXT:    [[LDEXP:%.*]] = tail call float @llvm.ldexp.f32.i32(float [[X]], i32 [[Y]])
219; CHECK-NEXT:    ret float [[LDEXP]]
220;
221  %ldexp = tail call float @_Z5ldexpfi(float %x, i32 %y)
222  ret float %ldexp
223}
224
225define float @test_ldexp_f32_nobuiltin(float %x, i32 %y) {
226; CHECK-LABEL: define float @test_ldexp_f32_nobuiltin
227; CHECK-SAME: (float [[X:%.*]], i32 [[Y:%.*]]) {
228; CHECK-NEXT:    [[LDEXP:%.*]] = tail call float @_Z5ldexpfi(float [[X]], i32 [[Y]]) #[[ATTR3:[0-9]+]]
229; CHECK-NEXT:    ret float [[LDEXP]]
230;
231  %ldexp = tail call float @_Z5ldexpfi(float %x, i32 %y) #0
232  ret float %ldexp
233}
234
235define float @test_ldexp_f32_strictfp(float %x, i32 %y) #4 {
236; CHECK-LABEL: define float @test_ldexp_f32_strictfp
237; CHECK-SAME: (float [[X:%.*]], i32 [[Y:%.*]]) #[[ATTR1:[0-9]+]] {
238; CHECK-NEXT:    [[LDEXP:%.*]] = tail call nnan float @_Z5ldexpfi(float [[X]], i32 [[Y]]) #[[ATTR1]]
239; CHECK-NEXT:    ret float [[LDEXP]]
240;
241  %ldexp = tail call nnan float @_Z5ldexpfi(float %x, i32 %y) #4
242  ret float %ldexp
243}
244
245;---------------------------------------------------------------------
246; Invalid signatures
247;---------------------------------------------------------------------
248
249; Declared with wrong type, second argument is float
250declare float @_Z5ldexpff(float noundef, float noundef)
251
252define float @call_wrong_typed_ldexp_f32_second_arg(float %x, float %wrongtype) {
253; CHECK-LABEL: define float @call_wrong_typed_ldexp_f32_second_arg
254; CHECK-SAME: (float [[X:%.*]], float [[WRONGTYPE:%.*]]) {
255; CHECK-NEXT:    [[CALL:%.*]] = call float @_Z5ldexpff(float [[X]], float [[WRONGTYPE]])
256; CHECK-NEXT:    ret float [[CALL]]
257;
258  %call = call float @_Z5ldexpff(float %x, float %wrongtype)
259  ret float %call
260}
261
262declare <2 x float> @_Z5ldexpDv2_fS_(<2 x float>, <2 x float>)
263
264define <2 x float> @call_wrong_typed_ldexp_v2f32_second_arg(<2 x float> %x, <2 x float> %wrongtype) {
265; CHECK-LABEL: define <2 x float> @call_wrong_typed_ldexp_v2f32_second_arg
266; CHECK-SAME: (<2 x float> [[X:%.*]], <2 x float> [[WRONGTYPE:%.*]]) {
267; CHECK-NEXT:    [[CALL:%.*]] = call <2 x float> @_Z5ldexpDv2_fS_(<2 x float> [[X]], <2 x float> [[WRONGTYPE]])
268; CHECK-NEXT:    ret <2 x float> [[CALL]]
269;
270  %call = call <2 x float> @_Z5ldexpDv2_fS_(<2 x float> %x, <2 x float> %wrongtype)
271  ret <2 x float> %call
272}
273
274declare <2 x float> @_Z5ldexpDv2_ff(<2 x float>, float)
275
276define <2 x float> @call_wrong_typed_ldexp_v2f32_f32(<2 x float> %x, float %wrongtype) {
277; CHECK-LABEL: define <2 x float> @call_wrong_typed_ldexp_v2f32_f32
278; CHECK-SAME: (<2 x float> [[X:%.*]], float [[WRONGTYPE:%.*]]) {
279; CHECK-NEXT:    [[CALL:%.*]] = call <2 x float> @_Z5ldexpDv2_ff(<2 x float> [[X]], float [[WRONGTYPE]])
280; CHECK-NEXT:    ret <2 x float> [[CALL]]
281;
282  %call = call <2 x float> @_Z5ldexpDv2_ff(<2 x float> %x, float %wrongtype)
283  ret <2 x float> %call
284}
285
286attributes #0 = { nobuiltin }
287attributes #1 = { "no-builtins" }
288attributes #2 = { nounwind memory(none) }
289attributes #3 = { minsize }
290attributes #4 = { strictfp }
291