Skip to content

Commit 621e957

Browse files
committed
Auto merge of rust-lang#125904 - workingjubilee:test-packed-simd-more, r=calebzulawski
Test codegen for `repr(packed,simd)` -> `repr(simd)` This adds the codegen test originally requested in rust-lang#117116 but exploiting the collection of features in FileCheck and compiletest to make it more resilient to expectations being broken by optimization levels. Mostly by presetting optimization levels for each revision of the tests. I do not think the dereferenceable attribute's presence or absence is that important. r? `@calebzulawski`
2 parents 865eaf9 + 9987363 commit 621e957

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Diff for: 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)