Skip to content

Commit 9987363

Browse files
Test codegen for repr(packed,simd) -> repr(simd)
1 parent eda9d7f commit 9987363

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/codegen/simd/packed-simd.rs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//@ revisions:opt3 noopt
2+
//@[opt3] compile-flags: -Copt-level=3
3+
//@[noopt] compile-flags: -Cno-prepopulate-passes
4+
5+
#![crate_type = "lib"]
6+
#![no_std]
7+
#![feature(repr_simd, core_intrinsics)]
8+
use core::intrinsics::simd as intrinsics;
9+
use core::{mem, ptr};
10+
11+
// Test codegen for not only "packed" but also "fully aligned" SIMD types, and conversion between
12+
// A repr(packed,simd) type with 3 elements can't exceed its element alignment,
13+
// whereas the same type as repr(simd) will instead have padding.
14+
15+
#[repr(simd, packed)]
16+
pub struct Simd<T, const N: usize>([T; N]);
17+
18+
#[repr(simd)]
19+
#[derive(Copy, Clone)]
20+
pub struct FullSimd<T, const N: usize>([T; N]);
21+
22+
// non-powers-of-two have padding and need to be expanded to full vectors
23+
fn load<T, const N: usize>(v: Simd<T, N>) -> FullSimd<T, N> {
24+
unsafe {
25+
let mut tmp = mem::MaybeUninit::<FullSimd<T, N>>::uninit();
26+
ptr::copy_nonoverlapping(&v as *const _, tmp.as_mut_ptr().cast(), 1);
27+
tmp.assume_init()
28+
}
29+
}
30+
31+
// CHECK-LABEL: square_packed
32+
// CHECK-SAME: ptr{{[a-z_ ]*}} sret([[RET_TYPE:[^)]+]]) [[RET_ALIGN:align (8|16)]]{{[^%]*}} [[RET_VREG:%[_0-9]*]]
33+
// CHECK-SAME: ptr{{[a-z_ ]*}} align 4
34+
#[no_mangle]
35+
pub fn square_packed(x: Simd<f32, 3>) -> FullSimd<f32, 3> {
36+
// CHECK-NEXT: start
37+
// noopt: alloca [[RET_TYPE]], [[RET_ALIGN]]
38+
// CHECK: load <3 x float>
39+
let x = load(x);
40+
// CHECK: [[VREG:%[a-z0-9_]+]] = fmul <3 x float>
41+
// CHECK-NEXT: store <3 x float> [[VREG]], ptr [[RET_VREG]], [[RET_ALIGN]]
42+
// CHECK-NEXT: ret void
43+
unsafe { intrinsics::simd_mul(x, x) }
44+
}

0 commit comments

Comments
 (0)