Skip to content
Open
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
4 changes: 3 additions & 1 deletion compiler/rustc_mir_transform/src/sroa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ fn escaping_locals<'tcx>(
return true;
}
if let ty::Adt(def, _args) = ty.kind()
&& (def.repr().simd() || tcx.is_lang_item(def.did(), LangItem::DynMetadata))
&& (def.repr().simd()
|| def.repr().scalable()
|| tcx.is_lang_item(def.did(), LangItem::DynMetadata))
{
// Exclude #[repr(simd)] types so that they are not de-optimized into an array
// (MCP#838 banned projections into SIMD types, but if the value is unused
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
);
}

if adt_def.repr().simd() {
if adt_def.repr().simd() || adt_def.repr().scalable() {

@scottmcm scottmcm Aug 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it worth having a negative test that mir-opt SRoA doesn't try to explode one of these, or similar?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added one now

self.fail(
location,
format!(
Expand Down
8 changes: 4 additions & 4 deletions library/stdarch/crates/core_arch/src/aarch64/sve/mod.rs
Comment thread
folkertdev marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<T> SveInto<T> for T {
macro_rules! impl_sve_type {
($(($v:vis, $elem_type:ty, $name:ident, $elt:literal))*) => ($(
#[doc = concat!("Scalable vector of type ", stringify!($elem_type))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy)]
#[rustc_scalable_vector($elt)]
#[unstable(feature = "stdarch_aarch64_sve", issue = "145052")]
$v struct $name($elem_type);
Expand All @@ -52,21 +52,21 @@ macro_rules! impl_sve_tuple_type {
)*);
(@ ($v:vis, $vec_type:ty, 2, $name:ident)) => (
#[doc = concat!("Two-element tuple of scalable vectors of type ", stringify!($vec_type))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy)]
#[rustc_scalable_vector]
#[unstable(feature = "stdarch_aarch64_sve", issue = "145052")]
$v struct $name($vec_type, $vec_type);
);
(@ ($v:vis, $vec_type:ty, 3, $name:ident)) => (
#[doc = concat!("Three-element tuple of scalable vectors of type ", stringify!($vec_type))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy)]
#[rustc_scalable_vector]
#[unstable(feature = "stdarch_aarch64_sve", issue = "145052")]
$v struct $name($vec_type, $vec_type, $vec_type);
);
(@ ($v:vis, $vec_type:ty, 4, $name:ident)) => (
#[doc = concat!("Four-element tuple of scalable vectors of type ", stringify!($vec_type))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy)]
#[rustc_scalable_vector]
#[unstable(feature = "stdarch_aarch64_sve", issue = "145052")]
$v struct $name($vec_type, $vec_type, $vec_type, $vec_type);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- // MIR for `bar` before ScalarReplacementOfAggregates
+ // MIR for `bar` after ScalarReplacementOfAggregates

fn bar(_1: &[svuint32x2_t], _2: svuint32x2_t) -> () {
debug simds => _1;
debug _unused => _2;
let mut _0: ();
let _3: std::arch::aarch64::svuint32x2_t;
let _4: usize;
let mut _5: usize;
let mut _6: bool;
scope 1 {
debug a => _3;
}

bb0: {
StorageLive(_3);
StorageLive(_4);
_4 = const 0_usize;
_5 = PtrMetadata(copy _1);
_6 = Lt(copy _4, copy _5);
assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, copy _4) -> [success: bb1, unwind continue];
}

bb1: {
_3 = copy (*_1)[_4];
StorageDead(_4);
StorageDead(_3);
return;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- // MIR for `foo` before ScalarReplacementOfAggregates
+ // MIR for `foo` after ScalarReplacementOfAggregates

fn foo(_1: &[svuint32_t], _2: svuint32_t) -> () {
debug simds => _1;
debug _unused => _2;
let mut _0: ();
let _3: std::arch::aarch64::svuint32_t;
let _4: usize;
let mut _5: usize;
let mut _6: bool;
scope 1 {
debug a => _3;
}

bb0: {
StorageLive(_3);
StorageLive(_4);
_4 = const 0_usize;
_5 = PtrMetadata(copy _1);
_6 = Lt(copy _4, copy _5);
assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, copy _4) -> [success: bb1, unwind continue];
}

bb1: {
_3 = copy (*_1)[_4];
StorageDead(_4);
StorageDead(_3);
return;
}
}

30 changes: 30 additions & 0 deletions tests/mir-opt/sroa/scalable_sroa.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//@ only-aarch64
//@ needs-unwind
#![feature(stdarch_aarch64_sve)]

// SRoA expands things even if they're unused
// <https://github.com/rust-lang/rust/issues/144621>

use std::arch::aarch64::{svuint32_t, svuint32x2_t};

// EMIT_MIR scalable_sroa.foo.ScalarReplacementOfAggregates.diff
pub(crate) fn foo(simds: &[svuint32_t], _unused: svuint32_t) {
// CHECK-LABEL: fn foo
// CHECK-NOT: u32
// CHECK: let [[SIMD:_.+]]: std::arch::aarch64::svuint32_t;
// CHECK-NOT: u32
// CHECK: [[SIMD]] = copy (*_1)[0 of 1];
// CHECK-NOT: u32
let a = simds[0];
}

// EMIT_MIR scalable_sroa.bar.ScalarReplacementOfAggregates.diff
pub(crate) fn bar(simds: &[svuint32x2_t], _unused: svuint32x2_t) {
// CHECK-LABEL: fn bar
// CHECK-NOT: { <vscale x u32 x 4>, <vscale x u32 x 4> }
// CHECK: let [[SIMD:_.+]]: std::arch::aarch64::svuint32x2_t;
// CHECK-NOT: { <vscale x u32 x 4>, <vscale x u32 x 4> }
// CHECK: [[SIMD]] = copy (*_1)[0 of 1];
// CHECK-NOT: { <vscale x u32 x 4>, <vscale x u32 x 4> }
let a = simds[0];
}
14 changes: 14 additions & 0 deletions tests/ui/scalable-vectors/auxiliary/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ add-minicore
//@ compile-flags: -Copt-level=0
//@ only-aarch64
#![feature(no_core, rustc_attrs)]
#![no_std]
#![no_core]
#![crate_type = "rlib"]
#![allow(internal_features)]

extern crate minicore;

#[allow(unused)] // Only used on aarch64-unknown-linux-gnu.
#[rustc_scalable_vector(4)]
pub struct Sv(f32);

@jhpratt jhpratt Aug 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to silence a lint.

@bors r- #160735 (comment)

---- [ui] tests/ui/scalable-vectors/project-into-field-extern.rs stdout ----

error: auxiliary build of /Users/runner/work/rust/rust/tests/ui/scalable-vectors/auxiliary/simple.rs failed to compile: 
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/stage2/bin/rustc" "/Users/runner/work/rust/rust/tests/ui/scalable-vectors/auxiliary/simple.rs" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/Users/runner/.cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/Users/runner/work/rust/rust/vendor" "--sysroot" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/stage2" "--target=aarch64-apple-darwin" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "--out-dir" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/Users/runner/work/rust/rust/build/aarch64-apple-darwin/native/rust-test-helpers" "-Cpanic=abort" "-Cforce-unwind-tables=yes" "-Copt-level=0" "--crate-type" "dylib" "-L" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary" "--extern" "minicore=/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/libminicore.rlib"
stdout: none
--- stderr -------------------------------
warning: field `0` is never read
##[warning]  --> /Users/runner/work/rust/rust/tests/ui/scalable-vectors/auxiliary/simple.rs:13:15
   |
LL | pub struct Sv(f32);
   |            -- ^^^
   |            |
   |            field in this struct
   |
   = help: consider removing this field
   = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

error: linking with `cc` failed: exit status: 1
   |
   = note:  "cc" "-Wl,-exported_symbols_list" "-Wl,/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary/rustcnDOBCi/list" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary/rustcnDOBCi/symbols.o" "<1 object files omitted>" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary/rustcnDOBCi/rmeta.o" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/libminicore.rlib" "-arch" "arm64" "-mmacosx-version-min=11.0.0" "-L" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/native/rust-test-helpers" "-L" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary" "-o" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary/libsimple.dylib" "-Wl,-dead_strip" "-dynamiclib" "-Wl,-install_name" "-Wl,@rpath/libsimple.dylib" "-nodefaultlibs"
   = note: some arguments are omitted. use `--verbose` to show all linker arguments
   = note: Undefined symbols for architecture arm64:
             "dyld_stub_binder", referenced from:
                 <initial-undefines>
           ld: symbol(s) not found for architecture arm64
           clang: error: linker command failed with exit code 1 (use -v to see invocation)
           

error: aborting due to 1 previous error; 1 warning emitted
------------------------------------------

View changes since the review

21 changes: 21 additions & 0 deletions tests/ui/scalable-vectors/project-into-field-extern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ add-minicore
//@ aux-build: simple.rs
//@ compile-flags: -Copt-level=0
//@ check-fail
//@ only-aarch64
#![feature(no_core, rustc_attrs)]
#![no_std]
#![no_core]
#![crate_type = "lib"]
#![allow(internal_features)]

extern crate minicore;
extern crate simple;

pub use simple::Sv;

#[target_feature(enable = "sve")]
pub fn field(x: Sv) -> f32 {
x.0
//~^ ERROR: field `0` of struct `Sv` is private
}
9 changes: 9 additions & 0 deletions tests/ui/scalable-vectors/project-into-field-extern.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0616]: field `0` of struct `Sv` is private
--> $DIR/project-into-field-extern.rs:19:7
|
LL | x.0
| ^ private field

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0616`.
24 changes: 24 additions & 0 deletions tests/ui/scalable-vectors/project-into-field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//@ add-minicore
//@ build-fail
//@ compile-flags: -Copt-level=0 --target=aarch64-unknown-linux-gnu
//@ dont-check-compiler-stderr
//@ failure-status: 101
//@ ignore-backends: gcc
//@ needs-llvm-components: aarch64
#![feature(no_core, rustc_attrs)]
#![no_std]
#![no_core]
#![crate_type = "lib"]
#![allow(internal_features)]

extern crate minicore;

#[rustc_scalable_vector(4)]
pub struct Sv(f32);

#[target_feature(enable = "sve")]
pub fn field(x: Sv) -> f32 {
x.0
//~^ ERROR broken MIR in Item
//~| ERROR Projecting into SIMD type Sv is banned by MCP#838
}
8 changes: 8 additions & 0 deletions tests/ui/scalable-vectors/project-into-field.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: cannot project into scalable vector type `Sv`
--> $DIR/project-into-field.rs:18:5
|
LL | x.0
| ^^^

error: aborting due to 1 previous error

Loading