fix bitcast of single-element SIMD vectors by folkertdev · Pull Request #143194 · rust-lang/rust (original) (raw)
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