Skip to content

fix bitcast of single-element SIMD vectors#143194

Merged
bors merged 1 commit intorust-lang:masterfrom
folkertdev:fix-single-element-simd-bitcast
Jul 2, 2025
Merged

fix bitcast of single-element SIMD vectors#143194
bors merged 1 commit intorust-lang:masterfrom
folkertdev:fix-single-element-simd-bitcast

Conversation

@folkertdev
Copy link
Copy Markdown
Contributor

in effect this reverts #142768 and adds additional tests. That PR relaxed the conditions on an early return in an incorrect way that would create broken LLVM IR.

https://godbolt.org/z/PaaGWTv5a

#![feature(repr_simd)]

#[repr(simd)]
#[derive(Clone, Copy)]
struct S([i64; 1]);

#[no_mangle]
pub extern "C" fn single_element_simd(b: S) -> i64 {
    unsafe { std::mem::transmute(b) }
}

at the time of writing generates this LLVM IR, where the type of the return is different from the function's return type.

define noundef i64 @single_element_simd(<1 x i64> %b) unnamed_addr {
start:
  ret <1 x i64> %b
}

The test output is actually the same for the existing tests, showing that the change didn't actually matter for any tested behavior. It is probably a bit faster to do the early return, but, well, it's incorrect in general.

zullip thread: #t-compiler > Is transmuting a `T` to `Tx1` (one-element SIMD vector) UB?
cc @sayantn
r? @scottmcm

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

9 participants