Skip to content

Projecting into non-power-of-two-lanes repr(simd) types does the wrong thing. #137108

New issue

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

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

Already on GitHub? # to your account

Open
scottmcm opened this issue Feb 16, 2025 · 2 comments
Open
Assignees
Labels
A-SIMD Area: SIMD (Single Instruction Multiple Data) requires-nightly This issue requires a nightly compiler in some way.

Comments

@scottmcm
Copy link
Member

scottmcm commented Feb 16, 2025

This is basically #105439 again. I'm assigning this to me because I think we should just ban it instead of making it work -- it's always problematic because vectors want to be immediates, but indexing wants things in-memory, so it'd be better to require insert/extract element on immediates.

EDIT: MCP to deem this unsupported rust-lang/compiler-team#838


Demo: https://rust.godbolt.org/z/Mr5edjzM9

#[inline(always)]
fn to_array3(a: i32x3) -> [i32; 3] {
    a.0
}

#[no_mangle]
pub fn simd_add_self_then_return_array_packed(a: i32x3) -> [i32; 3] {
    let b = unsafe { core::intrinsics::simd::simd_add(a, a) };
    to_array3(b)
}

Resulting IR on rustc 1.86.0-nightly (a567209 2025-02-13)

define void @simd_add_self_then_return_array_packed(ptr dead_on_unwind noalias nocapture noundef writable writeonly sret([12 x i8]) align 4 dereferenceable(12) %_0, ptr noalias nocapture noundef readonly align 16 dereferenceable(16) %a) unnamed_addr {
start:
  %0 = load i32, ptr %a, align 16
  %1 = shl i32 %0, 1
  store i32 %1, ptr %_0, align 4
  ret void
}

which is clearly wrong, since it only set one of the three i32s in the result array.

@scottmcm scottmcm self-assigned this Feb 16, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 16, 2025
@scottmcm scottmcm added A-SIMD Area: SIMD (Single Instruction Multiple Data) requires-nightly This issue requires a nightly compiler in some way. labels Feb 16, 2025
@scottmcm scottmcm added the I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness label Feb 21, 2025
@matthiaskrgr
Copy link
Member

#113465 (comment) seems to trigger a link to this issue 😅

@scottmcm scottmcm removed the I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness label Feb 24, 2025
@scottmcm
Copy link
Member Author

As of #137361 this now ICEs instead of being UB.

@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 1, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-SIMD Area: SIMD (Single Instruction Multiple Data) requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

No branches or pull requests

4 participants