]> git.proxmox.com Git - rustc.git/blame - tests/codegen/simd-intrinsic/simd-intrinsic-transmute-array.rs
Update upstream source from tag 'upstream/1.70.0+dfsg1'
[rustc.git] / tests / codegen / simd-intrinsic / simd-intrinsic-transmute-array.rs
CommitLineData
cdc7bbd5 1//
fc512014 2// compile-flags: -C no-prepopulate-passes
fc512014
XL
3
4#![crate_type = "lib"]
5
6#![allow(non_camel_case_types)]
353b0b11
FG
7#![feature(repr_simd, platform_intrinsics)]
8#![feature(inline_const)]
fc512014
XL
9
10#[repr(simd)]
11#[derive(Copy, Clone)]
12pub struct S<const N: usize>([f32; N]);
13
14#[repr(simd)]
15#[derive(Copy, Clone)]
16pub struct T([f32; 4]);
17
18#[repr(simd)]
19#[derive(Copy, Clone)]
20pub struct U(f32, f32, f32, f32);
21
353b0b11
FG
22// CHECK-LABEL: @array_align(
23#[no_mangle]
24pub fn array_align() -> usize {
25 // CHECK: ret [[USIZE:i[0-9]+]] [[ARRAY_ALIGN:[0-9]+]]
26 const { std::mem::align_of::<f32>() }
27}
28
29// CHECK-LABEL: @vector_align(
30#[no_mangle]
31pub fn vector_align() -> usize {
32 // CHECK: ret [[USIZE]] [[VECTOR_ALIGN:[0-9]+]]
33 const { std::mem::align_of::<U>() }
34}
35
fc512014
XL
36// CHECK-LABEL: @build_array_s
37#[no_mangle]
38pub fn build_array_s(x: [f32; 4]) -> S<4> {
353b0b11 39 // CHECK: call void @llvm.memcpy.{{.+}}({{.*}} align [[VECTOR_ALIGN]] {{.*}} align [[ARRAY_ALIGN]] {{.*}}, [[USIZE]] 16, i1 false)
fc512014
XL
40 S::<4>(x)
41}
42
353b0b11
FG
43// CHECK-LABEL: @build_array_transmute_s
44#[no_mangle]
45pub fn build_array_transmute_s(x: [f32; 4]) -> S<4> {
46 // CHECK: %[[VAL:.+]] = load <4 x float>, {{ptr %x|.+>\* %.+}}, align [[ARRAY_ALIGN]]
47 // CHECK: store <4 x float> %[[VAL:.+]], {{ptr %0|.+>\* %.+}}, align [[VECTOR_ALIGN]]
48 unsafe { std::mem::transmute(x) }
49}
50
fc512014
XL
51// CHECK-LABEL: @build_array_t
52#[no_mangle]
53pub fn build_array_t(x: [f32; 4]) -> T {
353b0b11 54 // CHECK: call void @llvm.memcpy.{{.+}}({{.*}} align [[VECTOR_ALIGN]] {{.*}} align [[ARRAY_ALIGN]] {{.*}}, [[USIZE]] 16, i1 false)
fc512014
XL
55 T(x)
56}
57
353b0b11
FG
58// CHECK-LABEL: @build_array_transmute_t
59#[no_mangle]
60pub fn build_array_transmute_t(x: [f32; 4]) -> T {
61 // CHECK: %[[VAL:.+]] = load <4 x float>, {{ptr %x|.+>\* %.+}}, align [[ARRAY_ALIGN]]
62 // CHECK: store <4 x float> %[[VAL:.+]], {{ptr %0|.+>\* %.+}}, align [[VECTOR_ALIGN]]
63 unsafe { std::mem::transmute(x) }
64}
65
fc512014
XL
66// CHECK-LABEL: @build_array_u
67#[no_mangle]
68pub fn build_array_u(x: [f32; 4]) -> U {
353b0b11
FG
69 // CHECK: store float %a, {{.+}}, align [[VECTOR_ALIGN]]
70 // CHECK: store float %b, {{.+}}, align [[ARRAY_ALIGN]]
71 // CHECK: store float %c, {{.+}}, align
72 // CHECK: store float %d, {{.+}}, align [[ARRAY_ALIGN]]
73 let [a, b, c, d] = x;
74 U(a, b, c, d)
75}
76
77// CHECK-LABEL: @build_array_transmute_u
78#[no_mangle]
79pub fn build_array_transmute_u(x: [f32; 4]) -> U {
80 // CHECK: %[[VAL:.+]] = load <4 x float>, {{ptr %x|.+>\* %.+}}, align [[ARRAY_ALIGN]]
81 // CHECK: store <4 x float> %[[VAL:.+]], {{ptr %0|.+>\* %.+}}, align [[VECTOR_ALIGN]]
fc512014
XL
82 unsafe { std::mem::transmute(x) }
83}