Skip to content

Commit 4fc2b26

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

File tree

1 file changed

+336
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)