rust/compiler/rustc_codegen_ssa/src/mir
Matthias Krüger 4f44014c5c
Rollup merge of #143194 - folkertdev:fix-single-element-simd-bitcast, r=workingjubilee
fix bitcast of single-element SIMD vectors

in effect this reverts https://github.com/rust-lang/rust/pull/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

```rust
#![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.

```llvm
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 &#96;T&#96; to &#96;Tx1&#96; (one-element SIMD vector) UB?](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Is.20transmuting.20a.20.60T.60.20to.20.60Tx1.60.20.28one-element.20SIMD.20vector.29.20UB.3F/with/526262799)
cc ``````@sayantn``````
r? ``````@scottmcm``````
2025-07-02 19:28:06 +02:00
..
analyze.rs Don't alloca just to look at a discriminant 2025-03-12 00:56:43 -07:00
block.rs Remove support for dyn* 2025-07-01 19:00:21 +00:00
constant.rs Stop relying on rustc_type_ir in non-type-system crates 2025-03-15 06:42:48 +00:00
coverageinfo.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
debuginfo.rs apply clippy::or_fun_call 2025-06-17 13:59:53 +03:00
intrinsic.rs Require either wrapping nullary intrinsincs in const blocks or explicitly deciding not to 2025-06-30 08:04:40 +00:00
locals.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
mod.rs mir: Add a new method to statement 2025-06-29 20:13:36 +08:00
naked_asm.rs centralize -Zmin-function-alignment logic 2025-06-22 00:47:10 +02:00
operand.rs move discr=varid check to layout_sanity_check 2025-06-28 14:47:27 +02:00
place.rs Change tag_field to FieldIdx in Variants::Multiple 2025-06-03 23:42:21 -07:00
rvalue.rs Rollup merge of #143194 - folkertdev:fix-single-element-simd-bitcast, r=workingjubilee 2025-07-02 19:28:06 +02:00
statement.rs reduce false positives of tail-expr-drop-order from consumed values 2024-11-20 20:53:11 +08:00