Skip to content

Commit d82f053

Browse files
committed
[IR] Add a test for f128 libcall lowering (NFC)
`f128` intrinsic functions sometimes lower to `long double` library calls when they instead need to be `f128` versions. Add a test demonstrating current behavior.
1 parent af223bc commit d82f053

File tree

1 file changed

+327
-0
lines changed

1 file changed

+327
-0
lines changed
Lines changed: 327 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,327 @@
1+
; RUN: %if aarch64-registered-target %{ llc < %s -mtriple=aarch64-unknown-none -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,CHECK-USELD %}
2+
; RUN: %if aarch64-registered-target %{ llc < %s -mtriple=aarch64-unknown-linux-gnu -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,CHECK-USELD %}
3+
; RUN: %if aarch64-registered-target %{ llc < %s -mtriple=aarch64-unknown-linux-musl -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,CHECK-USELD %}
4+
; RUN: %if arm-registered-target %{ llc < %s -mtriple=arm-none-eabi -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,CHECK-USELD %}
5+
; RUN: %if xfail-powerpc-registered-target %{ llc < %s -mtriple=powerpc-unknown -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,CHECK-F128 %}
6+
; RUN: %if xfail-powerpc-registered-target %{ llc < %s -mtriple=powerpc64-unknown -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,CHECK-F128 %}
7+
; RUN: %if riscv-registered-target %{ llc < %s -mtriple=riscv32-unknown -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,CHECK-USELD %}
8+
; RUN: %if systemz-registered-target %{ llc < %s -mtriple=s390x-unknown -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,CHECK-S390X %}
9+
; RUN: %if x86-registered-target %{ llc < %s -mtriple=i686-unknown -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,CHECK-USELD %}
10+
; RUN: %if x86-registered-target %{ llc < %s -mtriple=x86_64-unknown -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,CHECK-USELD %}
11+
;
12+
; Verify that fp128 intrinsics only lower to `long double` calls (e.g. sinl) on
13+
; platforms where 128 and `long double` have the same layout, and where the
14+
; `*f128` versions are known to not exist. Otherwise, lower to f128 versions
15+
; (e.g. sinf128).
16+
;
17+
; Targets include:
18+
; * aarch64 (long double == f128, should use ld syms)
19+
; * arm (long double == f64, should use f128 syms)
20+
; * s390x (long double == f128, should use ld syms, some hardware support)
21+
; * x86, x64 (80-bit long double, should use ld syms)
22+
; * gnu (has f128 symbols on all platforms so we can use those)
23+
; * musl (no f128 symbols available)
24+
25+
; FIXME: targets are configured so these tests pass, but the output has not
26+
; yet been corrected.
27+
28+
define fp128 @test_acos(fp128 %a) {
29+
; CHECK-LABEL: test_acos:
30+
; CHECK-F128: acosf128
31+
; CHECK-USELD: acosl
32+
; CHECK-S390X: acosl
33+
start:
34+
%0 = tail call fp128 @llvm.acos.f128(fp128 %a)
35+
ret fp128 %0
36+
}
37+
38+
define fp128 @test_asin(fp128 %a) {
39+
; CHECK-LABEL: test_asin:
40+
; CHECK-F128: asinf128
41+
; CHECK-USELD: asinl
42+
; CHECK-S390X: asinl
43+
start:
44+
%0 = tail call fp128 @llvm.asin.f128(fp128 %a)
45+
ret fp128 %0
46+
}
47+
48+
define fp128 @test_atan(fp128 %a) {
49+
; CHECK-LABEL: test_atan:
50+
; CHECK-F128: atanf128
51+
; CHECK-USELD: atanl
52+
; CHECK-S390X: atanl
53+
start:
54+
%0 = tail call fp128 @llvm.atan.f128(fp128 %a)
55+
ret fp128 %0
56+
}
57+
58+
define fp128 @test_ceil(fp128 %a) {
59+
; CHECK-LABEL: test_ceil:
60+
; CHECK-F128: ceilf128
61+
; CHECK-USELD: ceill
62+
; CHECK-S390X: ceill
63+
start:
64+
%0 = tail call fp128 @llvm.ceil.f128(fp128 %a)
65+
ret fp128 %0
66+
}
67+
68+
define fp128 @test_copysign(fp128 %a, fp128 %b) {
69+
; copysign should always get lowered to assembly.
70+
; CHECK-LABEL: test_copysign:
71+
; CHECK-NOT: copysignf128
72+
; CHECK-NOT: copysignl
73+
start:
74+
%0 = tail call fp128 @llvm.copysign.f128(fp128 %a, fp128 %b)
75+
ret fp128 %0
76+
}
77+
78+
define fp128 @test_cos(fp128 %a) {
79+
; CHECK-LABEL: test_cos:
80+
; CHECK-F128: cosf128
81+
; CHECK-USELD: cosl
82+
; CHECK-S390X: cosl
83+
start:
84+
%0 = tail call fp128 @llvm.cos.f128(fp128 %a)
85+
ret fp128 %0
86+
}
87+
88+
define fp128 @test_exp10(fp128 %a) {
89+
; CHECK-LABEL: test_exp10:
90+
; CHECK-F128: exp10f128
91+
; CHECK-USELD: exp10l
92+
; CHECK-S390X: exp10l
93+
start:
94+
%0 = tail call fp128 @llvm.exp10.f128(fp128 %a)
95+
ret fp128 %0
96+
}
97+
98+
define fp128 @test_exp2(fp128 %a) {
99+
; CHECK-LABEL: test_exp2:
100+
; CHECK-F128: exp2f128
101+
; CHECK-USELD: exp2l
102+
; CHECK-S390X: exp2l
103+
start:
104+
%0 = tail call fp128 @llvm.exp2.f128(fp128 %a)
105+
ret fp128 %0
106+
}
107+
108+
109+
define fp128 @test_exp(fp128 %a) {
110+
; CHECK-LABEL: test_exp:
111+
; CHECK-F128: expf128
112+
; CHECK-USELD: expl
113+
; CHECK-S390X: expl
114+
start:
115+
%0 = tail call fp128 @llvm.exp.f128(fp128 %a)
116+
ret fp128 %0
117+
}
118+
119+
define fp128 @test_fabs(fp128 %a) {
120+
; fabs should always get lowered to assembly.
121+
; CHECK-LABEL: test_fabs:
122+
; CHECK-NOT: fabsf128
123+
; CHECK-NOT: fabsl
124+
start:
125+
%0 = tail call fp128 @llvm.fabs.f128(fp128 %a)
126+
ret fp128 %0
127+
}
128+
129+
define fp128 @test_floor(fp128 %a) {
130+
; CHECK-LABEL: test_floor:
131+
; CHECK-F128: floorf128
132+
; CHECK-USELD: floorl
133+
; CHECK-S390X: floorl
134+
start:
135+
%0 = tail call fp128 @llvm.floor.f128(fp128 %a)
136+
ret fp128 %0
137+
}
138+
139+
define fp128 @test_fma(fp128 %a, fp128 %b, fp128 %c) {
140+
; CHECK-LABEL: test_fma:
141+
; CHECK-F128: fmaf128
142+
; CHECK-USELD: fmal
143+
; CHECK-S390X: fmal
144+
start:
145+
%0 = tail call fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c)
146+
ret fp128 %0
147+
}
148+
149+
define { fp128, i32 } @test_frexp(fp128 %a) {
150+
; CHECK-LABEL: test_frexp:
151+
; CHECK-F128: frexpf128
152+
; CHECK-USELD: frexpl
153+
; CHECK-S390X: frexpl
154+
start:
155+
%0 = tail call { fp128, i32 } @llvm.frexp.f128(fp128 %a)
156+
ret { fp128, i32 } %0
157+
}
158+
159+
define fp128 @test_ldexp(fp128 %a, i32 %b) {
160+
; CHECK-LABEL: test_ldexp:
161+
; CHECK-F128: ldexpf128
162+
; CHECK-USELD: ldexpl
163+
; CHECK-S390X: ldexpl
164+
start:
165+
%0 = tail call fp128 @llvm.ldexp.f128(fp128 %a, i32 %b)
166+
ret fp128 %0
167+
}
168+
169+
define i64 @test_llrint(fp128 %a) {
170+
; CHECK-LABEL: test_llrint:
171+
; CHECK-F128: llrintf128
172+
; CHECK-USELD: llrintl
173+
; CHECK-S390X: llrintl
174+
start:
175+
%0 = tail call i64 @llvm.llrint.f128(fp128 %a)
176+
ret i64 %0
177+
}
178+
179+
define i64 @test_llround(fp128 %a) {
180+
; CHECK-LABEL: test_llround:
181+
; CHECK-F128: llroundf128
182+
; CHECK-USELD: llroundl
183+
; CHECK-S390X: llroundl
184+
start:
185+
%0 = tail call i64 @llvm.llround.i64.f128(fp128 %a)
186+
ret i64 %0
187+
}
188+
189+
define fp128 @test_log10(fp128 %a) {
190+
; CHECK-LABEL: test_log10:
191+
; CHECK-F128: log10f128
192+
; CHECK-USELD: log10l
193+
; CHECK-S390X: log10l
194+
start:
195+
%0 = tail call fp128 @llvm.log10.f128(fp128 %a)
196+
ret fp128 %0
197+
}
198+
199+
define fp128 @test_log2(fp128 %a) {
200+
; CHECK-LABEL: test_log2:
201+
; CHECK-F128: log2f128
202+
; CHECK-USELD: log2l
203+
; CHECK-S390X: log2l
204+
start:
205+
%0 = tail call fp128 @llvm.log2.f128(fp128 %a)
206+
ret fp128 %0
207+
}
208+
209+
define fp128 @test_log(fp128 %a) {
210+
; CHECK-LABEL: test_log:
211+
; CHECK-F128: logf128
212+
; CHECK-USELD: logl
213+
; CHECK-S390X: logl
214+
start:
215+
%0 = tail call fp128 @llvm.log.f128(fp128 %a)
216+
ret fp128 %0
217+
}
218+
219+
define i64 @test_lrint(fp128 %a) {
220+
; CHECK-LABEL: test_lrint:
221+
; CHECK-F128: lrintf128
222+
; CHECK-USELD: lrintl
223+
; CHECK-S390X: lrintl
224+
start:
225+
%0 = tail call i64 @llvm.lrint.f128(fp128 %a)
226+
ret i64 %0
227+
}
228+
229+
define i64 @test_lround(fp128 %a) {
230+
; CHECK-LABEL: test_lround:
231+
; CHECK-F128: lroundf128
232+
; CHECK-USELD: lroundl
233+
; CHECK-S390X: lroundl
234+
start:
235+
%0 = tail call i64 @llvm.lround.i64.f128(fp128 %a)
236+
ret i64 %0
237+
}
238+
239+
define fp128 @test_nearbyint(fp128 %a) {
240+
; CHECK-LABEL: test_nearbyint:
241+
; CHECK-F128: nearbyintf128
242+
; CHECK-USELD: nearbyintl
243+
; CHECK-S390X: nearbyintl
244+
start:
245+
%0 = tail call fp128 @llvm.nearbyint.f128(fp128 %a)
246+
ret fp128 %0
247+
}
248+
249+
define fp128 @test_pow(fp128 %a, fp128 %b) {
250+
; CHECK-LABEL: test_pow:
251+
; CHECK-F128: powf128
252+
; CHECK-USELD: powl
253+
; CHECK-S390X: powl
254+
start:
255+
%0 = tail call fp128 @llvm.pow.f128(fp128 %a, fp128 %b)
256+
ret fp128 %0
257+
}
258+
259+
define fp128 @test_rint(fp128 %a) {
260+
; CHECK-LABEL: test_rint:
261+
; CHECK-F128: rintf128
262+
; CHECK-USELD: rintl
263+
; CHECK-S390X: fixbr {{%.*}}, 0, {{%.*}}
264+
start:
265+
%0 = tail call fp128 @llvm.rint.f128(fp128 %a)
266+
ret fp128 %0
267+
}
268+
269+
define fp128 @test_roundeven(fp128 %a) {
270+
; CHECK-LABEL: test_roundeven:
271+
; CHECK-F128: roundevenf128
272+
; CHECK-USELD: roundevenl
273+
; CHECK-S390X: roundevenl
274+
start:
275+
%0 = tail call fp128 @llvm.roundeven.f128(fp128 %a)
276+
ret fp128 %0
277+
}
278+
279+
define fp128 @test_round(fp128 %a) {
280+
; CHECK-LABEL: test_round:
281+
; CHECK-F128: roundf128
282+
; CHECK-USELD: roundl
283+
; CHECK-S390X: roundl
284+
start:
285+
%0 = tail call fp128 @llvm.round.f128(fp128 %a)
286+
ret fp128 %0
287+
}
288+
289+
define fp128 @test_sin(fp128 %a) {
290+
; CHECK-LABEL: test_sin:
291+
; CHECK-F128: sinf128
292+
; CHECK-USELD: sinl
293+
; CHECK-S390X: sinl
294+
start:
295+
%0 = tail call fp128 @llvm.sin.f128(fp128 %a)
296+
ret fp128 %0
297+
}
298+
299+
define fp128 @test_sqrt(fp128 %a) {
300+
; CHECK-LABEL: test_sqrt:
301+
; CHECK-F128: sqrtf128
302+
; CHECK-USELD: sqrtl
303+
; CHECK-S390X: sqxbr {{%.*}}, {{%.*}}
304+
start:
305+
%0 = tail call fp128 @llvm.sqrt.f128(fp128 %a)
306+
ret fp128 %0
307+
}
308+
309+
define fp128 @test_tan(fp128 %a) {
310+
; CHECK-LABEL: test_tan:
311+
; CHECK-F128: tanf128
312+
; CHECK-USELD: tanl
313+
; CHECK-S390X: tanl
314+
start:
315+
%0 = tail call fp128 @llvm.tan.f128(fp128 %a)
316+
ret fp128 %0
317+
}
318+
319+
define fp128 @test_trunc(fp128 %a) {
320+
; CHECK-LABEL: test_trunc:
321+
; CHECK-F128: truncf128
322+
; CHECK-USELD: truncl
323+
; CHECK-S390X: truncl
324+
start:
325+
%0 = tail call fp128 @llvm.trunc.f128(fp128 %a)
326+
ret fp128 %0
327+
}

0 commit comments

Comments
 (0)