Skip to content

Commit 0692047

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

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/codegen/simd/packed-simd.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
#[repr(simd, packed)]
12+
pub struct Simd<T, const N: usize>([T; N]);
13+
14+
#[repr(simd)]
15+
#[derive(Copy, Clone)]
16+
pub struct FullSimd<T, const N: usize>([T; N]);
17+
18+
// non-powers-of-two have padding and need to be expanded to full vectors
19+
fn load<T, const N: usize>(v: Simd<T, N>) -> FullSimd<T, N> {
20+
unsafe {
21+
let mut tmp = mem::MaybeUninit::<FullSimd<T, N>>::uninit();
22+
ptr::copy_nonoverlapping(&v as *const _, tmp.as_mut_ptr().cast(), 1);
23+
tmp.assume_init()
24+
}
25+
}
26+
27+
// CHECK-LABEL: square_packed
28+
// CHECK-SAME: ptr{{[a-z_ ]*}} sret([[RET_TYPE:[^)]+]]) [[RET_ALIGN:align (8|16)]]{{[^%]*}} [[RET_VREG:%[_0-9]*]]
29+
// CHECK-SAME: ptr{{[a-z_ ]*}} align 4
30+
#[no_mangle]
31+
pub fn square_packed(x: Simd<f32, 3>) -> FullSimd<f32, 3> {
32+
// CHECK-NEXT: start
33+
// We don't particularly care about the allocas and @llvm.lifetime.{start,end}
34+
// These merely serve as documentation for our current codegen.
35+
// noopt-DAG: alloca [[RET_TYPE]], [[RET_ALIGN]]
36+
// noopt-DAG: alloca{{.*}} align 4
37+
// noopt-NEXT: @llvm.lifetime.start
38+
// noopt-DAG: @llvm.lifetime.start
39+
// noopt-DAG: @llvm.memcpy.{{.*}}
40+
// noopt-DAG: @llvm.memcpy.{{.*}}ptr align 4 %{{[a-z0-9_]+}}, ptr align 4 %{{[a-z0-9_]+}}
41+
// With optimizations, everything up to here gets SRoA'd away
42+
// CHECK-NEXT: load <3 x float>
43+
let x = load(x);
44+
// noopt-NEXT: @llvm.lifetime.end
45+
// noopt-NEXT: @llvm.lifetime.end
46+
// CHECK: [[VREG:%[a-z0-9_]+]] = fmul <3 x float>
47+
// CHECK-NEXT: store <3 x float> [[VREG]], ptr [[RET_VREG]], [[RET_ALIGN]]
48+
// CHECK-NEXT: ret void
49+
unsafe { intrinsics::simd_mul(x, x) }
50+
}

0 commit comments

Comments
 (0)