Skip to content

Commit 4a507b1

Browse files
authored
WebAssembly: Add test for sincos intrinsic (#147467)
1 parent 0393084 commit 4a507b1

File tree

1 file changed

+393
-0
lines changed

1 file changed

+393
-0
lines changed
Lines changed: 393 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,393 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=wasm32-unknown-unknown < %s | FileCheck -check-prefixes=CHECK,WASM32 %s
3+
; RUN: llc -mtriple=wasm64-unknown-unknown < %s | FileCheck -check-prefixes=CHECK,WASM64 %s
4+
5+
define { half, half } @test_sincos_f16(half %a) #0 {
6+
; WASM32-LABEL: test_sincos_f16:
7+
; WASM32: .functype test_sincos_f16 (i32, f32) -> ()
8+
; WASM32-NEXT: # %bb.0:
9+
; WASM32-NEXT: local.get 0
10+
; WASM32-NEXT: local.get 1
11+
; WASM32-NEXT: call __truncsfhf2
12+
; WASM32-NEXT: call __extendhfsf2
13+
; WASM32-NEXT: local.tee 1
14+
; WASM32-NEXT: call cosf
15+
; WASM32-NEXT: call __truncsfhf2
16+
; WASM32-NEXT: i32.store16 2
17+
; WASM32-NEXT: local.get 0
18+
; WASM32-NEXT: local.get 1
19+
; WASM32-NEXT: call sinf
20+
; WASM32-NEXT: call __truncsfhf2
21+
; WASM32-NEXT: i32.store16 0
22+
; WASM32-NEXT: # fallthrough-return
23+
;
24+
; WASM64-LABEL: test_sincos_f16:
25+
; WASM64: .functype test_sincos_f16 (i64, f32) -> ()
26+
; WASM64-NEXT: # %bb.0:
27+
; WASM64-NEXT: local.get 0
28+
; WASM64-NEXT: local.get 1
29+
; WASM64-NEXT: call __truncsfhf2
30+
; WASM64-NEXT: call __extendhfsf2
31+
; WASM64-NEXT: local.tee 1
32+
; WASM64-NEXT: call cosf
33+
; WASM64-NEXT: call __truncsfhf2
34+
; WASM64-NEXT: i32.store16 2
35+
; WASM64-NEXT: local.get 0
36+
; WASM64-NEXT: local.get 1
37+
; WASM64-NEXT: call sinf
38+
; WASM64-NEXT: call __truncsfhf2
39+
; WASM64-NEXT: i32.store16 0
40+
; WASM64-NEXT: # fallthrough-return
41+
%result = call { half, half } @llvm.sincos.f16(half %a)
42+
ret { half, half } %result
43+
}
44+
45+
define half @test_sincos_f16_only_use_sin(half %a) #0 {
46+
; CHECK-LABEL: test_sincos_f16_only_use_sin:
47+
; CHECK: .functype test_sincos_f16_only_use_sin (f32) -> (f32)
48+
; CHECK-NEXT: # %bb.0:
49+
; CHECK-NEXT: local.get 0
50+
; CHECK-NEXT: call __truncsfhf2
51+
; CHECK-NEXT: call __extendhfsf2
52+
; CHECK-NEXT: call sinf
53+
; CHECK-NEXT: # fallthrough-return
54+
%result = call { half, half } @llvm.sincos.f16(half %a)
55+
%result.0 = extractvalue { half, half } %result, 0
56+
ret half %result.0
57+
}
58+
59+
define half @test_sincos_f16_only_use_cos(half %a) #0 {
60+
; CHECK-LABEL: test_sincos_f16_only_use_cos:
61+
; CHECK: .functype test_sincos_f16_only_use_cos (f32) -> (f32)
62+
; CHECK-NEXT: # %bb.0:
63+
; CHECK-NEXT: local.get 0
64+
; CHECK-NEXT: call __truncsfhf2
65+
; CHECK-NEXT: call __extendhfsf2
66+
; CHECK-NEXT: call cosf
67+
; CHECK-NEXT: # fallthrough-return
68+
%result = call { half, half } @llvm.sincos.f16(half %a)
69+
%result.1 = extractvalue { half, half } %result, 1
70+
ret half %result.1
71+
}
72+
73+
define { <2 x half>, <2 x half> } @test_sincos_v2f16(<2 x half> %a) #0 {
74+
; WASM32-LABEL: test_sincos_v2f16:
75+
; WASM32: .functype test_sincos_v2f16 (i32, f32, f32) -> ()
76+
; WASM32-NEXT: # %bb.0:
77+
; WASM32-NEXT: local.get 0
78+
; WASM32-NEXT: local.get 2
79+
; WASM32-NEXT: call __truncsfhf2
80+
; WASM32-NEXT: call __extendhfsf2
81+
; WASM32-NEXT: local.tee 2
82+
; WASM32-NEXT: call cosf
83+
; WASM32-NEXT: call __truncsfhf2
84+
; WASM32-NEXT: i32.store16 6
85+
; WASM32-NEXT: local.get 0
86+
; WASM32-NEXT: local.get 1
87+
; WASM32-NEXT: call __truncsfhf2
88+
; WASM32-NEXT: call __extendhfsf2
89+
; WASM32-NEXT: local.tee 1
90+
; WASM32-NEXT: call cosf
91+
; WASM32-NEXT: call __truncsfhf2
92+
; WASM32-NEXT: i32.store16 4
93+
; WASM32-NEXT: local.get 0
94+
; WASM32-NEXT: local.get 2
95+
; WASM32-NEXT: call sinf
96+
; WASM32-NEXT: call __truncsfhf2
97+
; WASM32-NEXT: i32.store16 2
98+
; WASM32-NEXT: local.get 0
99+
; WASM32-NEXT: local.get 1
100+
; WASM32-NEXT: call sinf
101+
; WASM32-NEXT: call __truncsfhf2
102+
; WASM32-NEXT: i32.store16 0
103+
; WASM32-NEXT: # fallthrough-return
104+
;
105+
; WASM64-LABEL: test_sincos_v2f16:
106+
; WASM64: .functype test_sincos_v2f16 (i64, f32, f32) -> ()
107+
; WASM64-NEXT: # %bb.0:
108+
; WASM64-NEXT: local.get 0
109+
; WASM64-NEXT: local.get 2
110+
; WASM64-NEXT: call __truncsfhf2
111+
; WASM64-NEXT: call __extendhfsf2
112+
; WASM64-NEXT: local.tee 2
113+
; WASM64-NEXT: call cosf
114+
; WASM64-NEXT: call __truncsfhf2
115+
; WASM64-NEXT: i32.store16 6
116+
; WASM64-NEXT: local.get 0
117+
; WASM64-NEXT: local.get 1
118+
; WASM64-NEXT: call __truncsfhf2
119+
; WASM64-NEXT: call __extendhfsf2
120+
; WASM64-NEXT: local.tee 1
121+
; WASM64-NEXT: call cosf
122+
; WASM64-NEXT: call __truncsfhf2
123+
; WASM64-NEXT: i32.store16 4
124+
; WASM64-NEXT: local.get 0
125+
; WASM64-NEXT: local.get 2
126+
; WASM64-NEXT: call sinf
127+
; WASM64-NEXT: call __truncsfhf2
128+
; WASM64-NEXT: i32.store16 2
129+
; WASM64-NEXT: local.get 0
130+
; WASM64-NEXT: local.get 1
131+
; WASM64-NEXT: call sinf
132+
; WASM64-NEXT: call __truncsfhf2
133+
; WASM64-NEXT: i32.store16 0
134+
; WASM64-NEXT: # fallthrough-return
135+
%result = call { <2 x half>, <2 x half> } @llvm.sincos.v2f16(<2 x half> %a)
136+
ret { <2 x half>, <2 x half> } %result
137+
}
138+
139+
define { float, float } @test_sincos_f32(float %a) #0 {
140+
; WASM32-LABEL: test_sincos_f32:
141+
; WASM32: .functype test_sincos_f32 (i32, f32) -> ()
142+
; WASM32-NEXT: # %bb.0:
143+
; WASM32-NEXT: local.get 0
144+
; WASM32-NEXT: local.get 1
145+
; WASM32-NEXT: call cosf
146+
; WASM32-NEXT: f32.store 4
147+
; WASM32-NEXT: local.get 0
148+
; WASM32-NEXT: local.get 1
149+
; WASM32-NEXT: call sinf
150+
; WASM32-NEXT: f32.store 0
151+
; WASM32-NEXT: # fallthrough-return
152+
;
153+
; WASM64-LABEL: test_sincos_f32:
154+
; WASM64: .functype test_sincos_f32 (i64, f32) -> ()
155+
; WASM64-NEXT: # %bb.0:
156+
; WASM64-NEXT: local.get 0
157+
; WASM64-NEXT: local.get 1
158+
; WASM64-NEXT: call cosf
159+
; WASM64-NEXT: f32.store 4
160+
; WASM64-NEXT: local.get 0
161+
; WASM64-NEXT: local.get 1
162+
; WASM64-NEXT: call sinf
163+
; WASM64-NEXT: f32.store 0
164+
; WASM64-NEXT: # fallthrough-return
165+
%result = call { float, float } @llvm.sincos.f32(float %a)
166+
ret { float, float } %result
167+
}
168+
169+
define { <2 x float>, <2 x float> } @test_sincos_v2f32(<2 x float> %a) #0 {
170+
; WASM32-LABEL: test_sincos_v2f32:
171+
; WASM32: .functype test_sincos_v2f32 (i32, f32, f32) -> ()
172+
; WASM32-NEXT: # %bb.0:
173+
; WASM32-NEXT: local.get 0
174+
; WASM32-NEXT: local.get 2
175+
; WASM32-NEXT: call cosf
176+
; WASM32-NEXT: f32.store 12
177+
; WASM32-NEXT: local.get 0
178+
; WASM32-NEXT: local.get 1
179+
; WASM32-NEXT: call cosf
180+
; WASM32-NEXT: f32.store 8
181+
; WASM32-NEXT: local.get 0
182+
; WASM32-NEXT: local.get 2
183+
; WASM32-NEXT: call sinf
184+
; WASM32-NEXT: f32.store 4
185+
; WASM32-NEXT: local.get 0
186+
; WASM32-NEXT: local.get 1
187+
; WASM32-NEXT: call sinf
188+
; WASM32-NEXT: f32.store 0
189+
; WASM32-NEXT: # fallthrough-return
190+
;
191+
; WASM64-LABEL: test_sincos_v2f32:
192+
; WASM64: .functype test_sincos_v2f32 (i64, f32, f32) -> ()
193+
; WASM64-NEXT: # %bb.0:
194+
; WASM64-NEXT: local.get 0
195+
; WASM64-NEXT: local.get 2
196+
; WASM64-NEXT: call cosf
197+
; WASM64-NEXT: f32.store 12
198+
; WASM64-NEXT: local.get 0
199+
; WASM64-NEXT: local.get 1
200+
; WASM64-NEXT: call cosf
201+
; WASM64-NEXT: f32.store 8
202+
; WASM64-NEXT: local.get 0
203+
; WASM64-NEXT: local.get 2
204+
; WASM64-NEXT: call sinf
205+
; WASM64-NEXT: f32.store 4
206+
; WASM64-NEXT: local.get 0
207+
; WASM64-NEXT: local.get 1
208+
; WASM64-NEXT: call sinf
209+
; WASM64-NEXT: f32.store 0
210+
; WASM64-NEXT: # fallthrough-return
211+
%result = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> %a)
212+
ret { <2 x float>, <2 x float> } %result
213+
}
214+
215+
define { <3 x float>, <3 x float> } @test_sincos_v3f32(<3 x float> %a) #0 {
216+
; WASM32-LABEL: test_sincos_v3f32:
217+
; WASM32: .functype test_sincos_v3f32 (i32, f32, f32, f32) -> ()
218+
; WASM32-NEXT: # %bb.0:
219+
; WASM32-NEXT: local.get 0
220+
; WASM32-NEXT: local.get 3
221+
; WASM32-NEXT: call cosf
222+
; WASM32-NEXT: f32.store 24
223+
; WASM32-NEXT: local.get 0
224+
; WASM32-NEXT: local.get 3
225+
; WASM32-NEXT: call sinf
226+
; WASM32-NEXT: f32.store 8
227+
; WASM32-NEXT: local.get 2
228+
; WASM32-NEXT: call cosf
229+
; WASM32-NEXT: local.set 3
230+
; WASM32-NEXT: local.get 0
231+
; WASM32-NEXT: local.get 1
232+
; WASM32-NEXT: call cosf
233+
; WASM32-NEXT: i32.reinterpret_f32
234+
; WASM32-NEXT: i64.extend_i32_u
235+
; WASM32-NEXT: local.get 3
236+
; WASM32-NEXT: i32.reinterpret_f32
237+
; WASM32-NEXT: i64.extend_i32_u
238+
; WASM32-NEXT: i64.const 32
239+
; WASM32-NEXT: i64.shl
240+
; WASM32-NEXT: i64.or
241+
; WASM32-NEXT: i64.store 16
242+
; WASM32-NEXT: local.get 2
243+
; WASM32-NEXT: call sinf
244+
; WASM32-NEXT: local.set 3
245+
; WASM32-NEXT: local.get 0
246+
; WASM32-NEXT: local.get 1
247+
; WASM32-NEXT: call sinf
248+
; WASM32-NEXT: i32.reinterpret_f32
249+
; WASM32-NEXT: i64.extend_i32_u
250+
; WASM32-NEXT: local.get 3
251+
; WASM32-NEXT: i32.reinterpret_f32
252+
; WASM32-NEXT: i64.extend_i32_u
253+
; WASM32-NEXT: i64.const 32
254+
; WASM32-NEXT: i64.shl
255+
; WASM32-NEXT: i64.or
256+
; WASM32-NEXT: i64.store 0
257+
; WASM32-NEXT: # fallthrough-return
258+
;
259+
; WASM64-LABEL: test_sincos_v3f32:
260+
; WASM64: .functype test_sincos_v3f32 (i64, f32, f32, f32) -> ()
261+
; WASM64-NEXT: # %bb.0:
262+
; WASM64-NEXT: local.get 0
263+
; WASM64-NEXT: local.get 3
264+
; WASM64-NEXT: call cosf
265+
; WASM64-NEXT: f32.store 24
266+
; WASM64-NEXT: local.get 0
267+
; WASM64-NEXT: local.get 3
268+
; WASM64-NEXT: call sinf
269+
; WASM64-NEXT: f32.store 8
270+
; WASM64-NEXT: local.get 2
271+
; WASM64-NEXT: call cosf
272+
; WASM64-NEXT: local.set 3
273+
; WASM64-NEXT: local.get 0
274+
; WASM64-NEXT: local.get 1
275+
; WASM64-NEXT: call cosf
276+
; WASM64-NEXT: i32.reinterpret_f32
277+
; WASM64-NEXT: i64.extend_i32_u
278+
; WASM64-NEXT: local.get 3
279+
; WASM64-NEXT: i32.reinterpret_f32
280+
; WASM64-NEXT: i64.extend_i32_u
281+
; WASM64-NEXT: i64.const 32
282+
; WASM64-NEXT: i64.shl
283+
; WASM64-NEXT: i64.or
284+
; WASM64-NEXT: i64.store 16
285+
; WASM64-NEXT: local.get 2
286+
; WASM64-NEXT: call sinf
287+
; WASM64-NEXT: local.set 3
288+
; WASM64-NEXT: local.get 0
289+
; WASM64-NEXT: local.get 1
290+
; WASM64-NEXT: call sinf
291+
; WASM64-NEXT: i32.reinterpret_f32
292+
; WASM64-NEXT: i64.extend_i32_u
293+
; WASM64-NEXT: local.get 3
294+
; WASM64-NEXT: i32.reinterpret_f32
295+
; WASM64-NEXT: i64.extend_i32_u
296+
; WASM64-NEXT: i64.const 32
297+
; WASM64-NEXT: i64.shl
298+
; WASM64-NEXT: i64.or
299+
; WASM64-NEXT: i64.store 0
300+
; WASM64-NEXT: # fallthrough-return
301+
%result = call { <3 x float>, <3 x float> } @llvm.sincos.v3f32(<3 x float> %a)
302+
ret { <3 x float>, <3 x float> } %result
303+
}
304+
305+
define { double, double } @test_sincos_f64(double %a) #0 {
306+
; WASM32-LABEL: test_sincos_f64:
307+
; WASM32: .functype test_sincos_f64 (i32, f64) -> ()
308+
; WASM32-NEXT: # %bb.0:
309+
; WASM32-NEXT: local.get 0
310+
; WASM32-NEXT: local.get 1
311+
; WASM32-NEXT: call cos
312+
; WASM32-NEXT: f64.store 8
313+
; WASM32-NEXT: local.get 0
314+
; WASM32-NEXT: local.get 1
315+
; WASM32-NEXT: call sin
316+
; WASM32-NEXT: f64.store 0
317+
; WASM32-NEXT: # fallthrough-return
318+
;
319+
; WASM64-LABEL: test_sincos_f64:
320+
; WASM64: .functype test_sincos_f64 (i64, f64) -> ()
321+
; WASM64-NEXT: # %bb.0:
322+
; WASM64-NEXT: local.get 0
323+
; WASM64-NEXT: local.get 1
324+
; WASM64-NEXT: call cos
325+
; WASM64-NEXT: f64.store 8
326+
; WASM64-NEXT: local.get 0
327+
; WASM64-NEXT: local.get 1
328+
; WASM64-NEXT: call sin
329+
; WASM64-NEXT: f64.store 0
330+
; WASM64-NEXT: # fallthrough-return
331+
%result = call { double, double } @llvm.sincos.f64(double %a)
332+
ret { double, double } %result
333+
}
334+
335+
define { <2 x double>, <2 x double> } @test_sincos_v2f64(<2 x double> %a) #0 {
336+
; WASM32-LABEL: test_sincos_v2f64:
337+
; WASM32: .functype test_sincos_v2f64 (i32, f64, f64) -> ()
338+
; WASM32-NEXT: # %bb.0:
339+
; WASM32-NEXT: local.get 0
340+
; WASM32-NEXT: local.get 2
341+
; WASM32-NEXT: call cos
342+
; WASM32-NEXT: f64.store 24
343+
; WASM32-NEXT: local.get 0
344+
; WASM32-NEXT: local.get 1
345+
; WASM32-NEXT: call cos
346+
; WASM32-NEXT: f64.store 16
347+
; WASM32-NEXT: local.get 0
348+
; WASM32-NEXT: local.get 2
349+
; WASM32-NEXT: call sin
350+
; WASM32-NEXT: f64.store 8
351+
; WASM32-NEXT: local.get 0
352+
; WASM32-NEXT: local.get 1
353+
; WASM32-NEXT: call sin
354+
; WASM32-NEXT: f64.store 0
355+
; WASM32-NEXT: # fallthrough-return
356+
;
357+
; WASM64-LABEL: test_sincos_v2f64:
358+
; WASM64: .functype test_sincos_v2f64 (i64, f64, f64) -> ()
359+
; WASM64-NEXT: # %bb.0:
360+
; WASM64-NEXT: local.get 0
361+
; WASM64-NEXT: local.get 2
362+
; WASM64-NEXT: call cos
363+
; WASM64-NEXT: f64.store 24
364+
; WASM64-NEXT: local.get 0
365+
; WASM64-NEXT: local.get 1
366+
; WASM64-NEXT: call cos
367+
; WASM64-NEXT: f64.store 16
368+
; WASM64-NEXT: local.get 0
369+
; WASM64-NEXT: local.get 2
370+
; WASM64-NEXT: call sin
371+
; WASM64-NEXT: f64.store 8
372+
; WASM64-NEXT: local.get 0
373+
; WASM64-NEXT: local.get 1
374+
; WASM64-NEXT: call sin
375+
; WASM64-NEXT: f64.store 0
376+
; WASM64-NEXT: # fallthrough-return
377+
%result = call { <2 x double>, <2 x double> } @llvm.sincos.v2f64(<2 x double> %a)
378+
ret { <2 x double>, <2 x double> } %result
379+
}
380+
381+
; ; FIXME: Asserts
382+
; define { fp128, fp128 } @test_sincos_f128(fp128 %a) #0 {
383+
; %result = call { fp128, fp128 } @llvm.sincos.f128(fp128 %a)
384+
; ret { fp128, fp128 } %result
385+
; }
386+
387+
; ; FIXME: Asserts
388+
; define { <2 x fp128>, <2 x fp128> } @test_sincos_v2f128(<2 x fp128> %a) #0 {
389+
; %result = call { <2 x fp128>, <2 x fp128> } @llvm.sincos.v2f128(<2 x fp128> %a)
390+
; ret { <2 x fp128>, <2 x fp128> } %result
391+
; }
392+
393+
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)