Skip to content

Commit b371713

Browse files
Rollup merge of #157768 - davidtwco:scalable-vector-transparent-wrapper, r=lqd
codegen_ssa: peel trans. wrappers on scalable vecs Transparent wrappers around scalable vectors like `MaybeUninit<svuint32_t>` need alloca of scalable vector types, which requires peeling off transparent wrappers so the correct code path is used.
2 parents c926a93 + bd8e734 commit b371713

2 files changed

Lines changed: 56 additions & 2 deletions

File tree

compiler/rustc_codegen_ssa/src/mir/place.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
111111
bx: &mut Bx,
112112
layout: TyAndLayout<'tcx>,
113113
) -> Self {
114-
if layout.deref().is_scalable_vector() {
114+
if layout.peel_transparent_wrappers(bx).deref().is_scalable_vector() {
115115
Self::alloca_scalable(bx, layout)
116116
} else {
117117
Self::alloca_size(bx, layout.size, layout)
@@ -157,7 +157,11 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
157157
bx: &mut Bx,
158158
layout: TyAndLayout<'tcx>,
159159
) -> Self {
160-
PlaceValue::new_sized(bx.alloca_with_ty(layout), layout.align.abi).with_type(layout)
160+
PlaceValue::new_sized(
161+
bx.alloca_with_ty(layout.peel_transparent_wrappers(bx)),
162+
layout.align.abi,
163+
)
164+
.with_type(layout)
161165
}
162166
}
163167

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//@ only-aarch64
2+
//@ build-pass
3+
//@ compile-flags: --emit=obj -Ctarget-feature=+sve
4+
//@ edition:2021
5+
#![feature(simd_ffi)]
6+
#![feature(stdarch_aarch64_sve)]
7+
8+
use std::arch::aarch64::*;
9+
10+
// Tests that scalable vectors in transparent wrapper types compile correctly (that is, that
11+
// alloca we generate in LLVM IR are for scalable vector types and not arrays, because rustc
12+
// looks through the transparent wrapper).
13+
14+
static I16_147: [i16; 147] = [
15+
0x0, 0x400, 0x37ff, 0x3800, 0x3801, 0x3bff, 0x3c00, 0x3c01, 0x3e00, 0x4900, 0x7bff, 0x7c00,
16+
0x7f23, 0x7e00, 0x7d23, 0x7c01, 0x12, 0x3ff, 0x1, -0x8000, -0x7c00, -0x4801, -0x4800, -0x47ff,
17+
-0x4401, -0x4400, -0x43ff, -0x4200, -0x3700, -0x401, -0x400, -0xdd, -0x200, -0x2dd, -0x3ff,
18+
-0x7fee, -0x7c01, -0x7fff, -0x400, -0x4000, 0x5140, 0x5800, 0x63d2, 0x5630, 0x3560, -0x6e6f,
19+
0x4178, 0x6212, 0x67d0, 0x3312, 0x4cef, 0x4973, 0x3ecc, 0x5166, 0x4d80, 0x6248, 0x46fd, 0x39c4,
20+
0x39c5, 0x4866, 0x6050, 0x498e, 0x4a0f, 0x3555, -0x400, -0x4000, -0x6e6f, 0x5140, 0x5800,
21+
-0x7fff, -0x7c01, 0x63d2, 0x5630, 0x3560, 0x4178, 0x7d23, 0x7c01, 0x12, -0x4800, 0x3ff, 0x1,
22+
0x7e00, 0x7f23, -0x8000, -0x7c00, -0x4801, -0x47ff, 0x3312, 0x4cef, 0x4973, 0x39c4, 0x3ecc,
23+
0x5166, 0x67d0, 0x6212, 0x4d80, 0x6248, 0x46fd, 0x39c5, -0x43ff, -0x4200, -0x3700, -0x3ff,
24+
-0x401, -0x400, -0x4400, -0x4401, -0xdd, -0x200, -0x2dd, -0x7fee, 0x37ff, 0x3800, 0x3801,
25+
0x7bff, 0x3bff, 0x3c00, 0x400, 0x0, 0x3c01, 0x3e00, 0x4900, 0x7c00, 0x498e, 0x4a0f, 0x6050,
26+
0x4866, 0x3555, 0x0, 0x400, 0x37ff, 0x3800, 0x3801, 0x3bff, 0x3c00, 0x3c01, 0x3e00, 0x4900,
27+
0x7bff, 0x7c00, 0x7f23, 0x7e00, 0x7d23, 0x7c01, 0x12, 0x3ff, 0x1,
28+
];
29+
30+
#[allow(improper_ctypes)]
31+
unsafe extern "C" {
32+
fn svcreate2_s16_wrapper(__dst: *mut svint16x2_t, x0: *const svint16_t, x1: *const svint16_t);
33+
}
34+
35+
fn main() {
36+
unsafe {
37+
let __pred = svptrue_b16();
38+
let x0_val = svld1_s16(__pred, I16_147.as_ptr().add(0) as _);
39+
40+
let mut __c_return_value = std::mem::MaybeUninit::uninit();
41+
svcreate2_s16_wrapper(__c_return_value.as_mut_ptr(), &raw const x0_val, &raw const x0_val);
42+
let __c_return_value = __c_return_value.assume_init();
43+
44+
let eq = svcmpeq_s16(
45+
__pred,
46+
svget2_s16::<0>(__c_return_value),
47+
svget2_s16::<0>(__c_return_value),
48+
);
49+
}
50+
}

0 commit comments

Comments
 (0)