Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simd packed types: remove outdated comment, extend codegen test #126163

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,10 +1109,12 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), callee_ty.fn_sig(tcx));
let arg_tys = sig.inputs();

// Vectors must be immediates (non-power-of-2 #[repr(packed)] are not)
for (ty, arg) in arg_tys.iter().zip(args) {
if ty.is_simd() && !matches!(arg.val, OperandValue::Immediate(_)) {
return_error!(InvalidMonomorphization::SimdArgument { span, name, ty: *ty });
// Sanity-check: all vector arguments must be immediates.
if cfg!(debug_assertions) {
for (ty, arg) in arg_tys.iter().zip(args) {
if ty.is_simd() {
assert!(matches!(arg.val, OperandValue::Immediate(_)));
}
}
}

Expand Down
23 changes: 19 additions & 4 deletions tests/codegen/simd/packed-simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ use core::intrinsics::simd as intrinsics;
use core::{mem, ptr};

// Test codegen for not only "packed" but also "fully aligned" SIMD types, and conversion between
// A repr(packed,simd) type with 3 elements can't exceed its element alignment,
// whereas the same type as repr(simd) will instead have padding.
// them. A repr(packed,simd) type with 3 elements can't exceed its element alignment, whereas the
// same type as repr(simd) will instead have padding.

#[repr(simd, packed)]
#[derive(Copy, Clone)]
pub struct Simd<T, const N: usize>([T; N]);

#[repr(simd)]
Expand All @@ -28,11 +29,11 @@ fn load<T, const N: usize>(v: Simd<T, N>) -> FullSimd<T, N> {
}
}

// CHECK-LABEL: square_packed
// CHECK-LABEL: square_packed_full
// CHECK-SAME: ptr{{[a-z_ ]*}} sret([[RET_TYPE:[^)]+]]) [[RET_ALIGN:align (8|16)]]{{[^%]*}} [[RET_VREG:%[_0-9]*]]
// CHECK-SAME: ptr{{[a-z_ ]*}} align 4
#[no_mangle]
pub fn square_packed(x: Simd<f32, 3>) -> FullSimd<f32, 3> {
pub fn square_packed_full(x: Simd<f32, 3>) -> FullSimd<f32, 3> {
// CHECK-NEXT: start
// noopt: alloca [[RET_TYPE]], [[RET_ALIGN]]
// CHECK: load <3 x float>
Expand All @@ -42,3 +43,17 @@ pub fn square_packed(x: Simd<f32, 3>) -> FullSimd<f32, 3> {
// CHECK-NEXT: ret void
unsafe { intrinsics::simd_mul(x, x) }
}

// CHECK-LABEL: square_packed
// CHECK-SAME: ptr{{[a-z_ ]*}} sret([[RET_TYPE:[^)]+]]) [[RET_ALIGN:align 4]]{{[^%]*}} [[RET_VREG:%[_0-9]*]]
// CHECK-SAME: ptr{{[a-z_ ]*}} align 4
#[no_mangle]
pub fn square_packed(x: Simd<f32, 3>) -> Simd<f32, 3> {
// CHECK-NEXT: start
// CHECK-NEXT: load <3 x float>
// noopt-NEXT: load <3 x float>
// CHECK-NEXT: [[VREG:%[a-z0-9_]+]] = fmul <3 x float>
// CHECK-NEXT: store <3 x float> [[VREG]], ptr [[RET_VREG]], [[RET_ALIGN]]
// CHECK-NEXT: ret void
unsafe { intrinsics::simd_mul(x, x) }
}
Loading