Skip to content

Commit 853c948

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 1e58735 commit 853c948

File tree

1 file changed

+337
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)