From c623489b9bb5ad8dcb1094197710364b137d8b49 Mon Sep 17 00:00:00 2001 From: Caleb Zulawski Date: Sat, 18 Nov 2023 11:22:55 -0500 Subject: [PATCH] Add codegen test --- tests/codegen/simd/repr-packed.rs | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/codegen/simd/repr-packed.rs diff --git a/tests/codegen/simd/repr-packed.rs b/tests/codegen/simd/repr-packed.rs new file mode 100644 index 00000000000..27b9821cbe5 --- /dev/null +++ b/tests/codegen/simd/repr-packed.rs @@ -0,0 +1,32 @@ +// compile-flags: -C no-prepopulate-passes + +#![crate_type = "lib"] +#![feature(repr_simd, platform_intrinsics)] + +#[repr(simd, packed)] +pub struct Simd([T; N]); + +#[repr(simd)] +#[derive(Copy, Clone)] +pub struct FullSimd([T; N]); + +extern "platform-intrinsic" { + fn simd_mul(a: T, b: T) -> T; +} + +// non-powers-of-two have padding and need to be expanded to full vectors +fn load(v: Simd) -> FullSimd { + unsafe { + let mut tmp = core::mem::MaybeUninit::>::uninit(); + std::ptr::copy_nonoverlapping(&v as *const _, tmp.as_mut_ptr().cast(), 1); + tmp.assume_init() + } +} + +// CHECK-LABEL: @square_packed +#[no_mangle] +pub fn square_packed(x: Simd) -> FullSimd { + // CHECK: align 4 dereferenceable(12) %x + let x = load(x); + unsafe { simd_mul(x, x) } +}