Skip to content

preserve SIMD element type information#155005

Open
folkertdev wants to merge 1 commit intorust-lang:mainfrom
folkertdev:simd-element-type-llvm
Open

preserve SIMD element type information#155005
folkertdev wants to merge 1 commit intorust-lang:mainfrom
folkertdev:simd-element-type-llvm

Conversation

@folkertdev
Copy link
Copy Markdown
Contributor

@folkertdev folkertdev commented Apr 8, 2026

Preserve the SIMD element type and provide it to LLVM for better optimization.

This is relevant for AArch64 types like int16x4x2_t, see also llvm/llvm-project#181514. Such types are defined like so:

#[repr(simd)]
struct int16x4_t([i16; 4]);

#[repr(C)]
struct int16x4x2_t(pub int16x4_t, pub int16x4_t);

Previously this would be translated to the opaque [2 x <8 x i8>], with this PR it is instead [2 x <4 x i16>]. That change is not relevant for the ABI, but using the correct type prevents bitcasts that can (indeed, do) confuse the LLVM pattern matcher.

This change will make it possible to implement the deinterleaving loads on AArch64 in a portable way (without neon-specific intrinsics), which means that e.g. Miri or the cranelift backend can run them without additional support.

discussion at #t-compiler > loss of vector element type information

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 8, 2026
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the simd-element-type-llvm branch from c1444a0 to 05b0368 Compare April 8, 2026 20:40
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the simd-element-type-llvm branch 2 times, most recently from 93d1e47 to c9dd7e6 Compare April 9, 2026 09:42
and provide it to LLVM for better optimization
@folkertdev folkertdev force-pushed the simd-element-type-llvm branch from c9dd7e6 to 68ed562 Compare April 9, 2026 09:51
@folkertdev folkertdev marked this pull request as ready for review April 9, 2026 15:26
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 9, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 9, 2026

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 9, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 9, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 11 candidates

// CHECK: define [2 x <1 x ptr>] @pair_ptrx1_t([2 x <1 x ptr>] {{.*}} %0)
#[unsafe(no_mangle)] extern "C" fn pair_ptrx1_t(x: Pair<Simd<*const (), 1>>) -> Pair<Simd<*const (), 1>> { x }

// When it fits in a 128-bit register, it's passed directly.
Copy link
Copy Markdown
Contributor Author

@folkertdev folkertdev Apr 9, 2026

Choose a reason for hiding this comment

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

View changes since the review

the types above are actually used by neon intrinsics. Below are a couple that technically work but are unlikely to come up practically.

Then for any type is smaller than 128-bit padding is added which means the type information is lost (but I think that is needed for ABI reasons?). Larger types are passed indirectly, so the type information is not needed there (but we do still technically provide it, maybe it's useful elsewhere).

@folkertdev folkertdev changed the title preseve SIMD element type information preserve SIMD element type information Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants