rust/compiler/rustc_codegen_ssa/src
Matthias Krüger 3a69035338
Rollup merge of #151346 - folkertdev:simd-splat, r=workingjubilee
add `simd_splat` intrinsic

Add `simd_splat` which lowers to the LLVM canonical splat sequence.

```llvm
insertelement <N x elem> poison, elem %x, i32 0
shufflevector <N x elem> v0, <N x elem> poison, <N x i32> zeroinitializer
```

Right now we try to fake it using one of

```rust
fn splat(x: u32) -> u32x8 {
    u32x8::from_array([x; 8])
}
```

or (in `stdarch`)

```rust
fn splat(value: $elem_type) -> $name {
    #[derive(Copy, Clone)]
    #[repr(simd)]
    struct JustOne([$elem_type; 1]);
    let one = JustOne([value]);
    // SAFETY: 0 is always in-bounds because we're shuffling
    // a simd type with exactly one element.
    unsafe { simd_shuffle!(one, one, [0; $len]) }
}
```

Both of these can confuse the LLVM optimizer, producing sub-par code. Some examples:

- https://github.com/rust-lang/rust/issues/60637
- https://github.com/rust-lang/rust/issues/137407
- https://github.com/rust-lang/rust/issues/122623
- https://github.com/rust-lang/rust/issues/97804

---

As far as I can tell there is no way to provide a fallback implementation for this intrinsic, because there is no `const` way of evaluating the number of elements (there might be issues beyond that, too). So, I added implementations for all 4 backends.

Both GCC and const-eval appear to have some issues with simd vectors containing pointers. I have a workaround for GCC, but haven't yet been able to make const-eval work. See the comments below.

Currently this just adds the intrinsic, it does not actually use it anywhere yet.
2026-01-24 21:04:15 +01:00
..
back Auto merge of #149848 - bjorn3:alloc_shim_rework2, r=jackh726 2026-01-24 07:04:14 +00:00
debuginfo Support debuginfo for assoc const bindings 2026-01-21 18:52:08 +01:00
mir Rollup merge of #151346 - folkertdev:simd-splat, r=workingjubilee 2026-01-24 21:04:15 +01:00
traits Rollup merge of #151465 - RalfJung:fn-call-vars, r=mati865 2026-01-22 13:35:42 +01:00
assert_module_sources.rs Print CGU reuse statistics when -Zprint-mono-items is enabled 2025-08-04 15:43:50 +02:00
base.rs Port crate_type to attribute parser 2026-01-22 02:34:28 +00:00
codegen_attrs.rs Port #![no_builtins] to the attribute parser. 2026-01-21 21:08:28 +00:00
common.rs rustc_target: introduce Os 2025-11-11 18:55:40 -05:00
errors.rs Port #[patchable_function_entry] to attr parser 2026-01-20 11:46:05 +01:00
lib.rs Remove all allows for diagnostic_outside_of_impl and untranslatable_diagnostic throughout the codebase 2026-01-19 17:39:49 +01:00
meth.rs Remove DynKind 2025-09-17 04:46:46 +02:00
mono_item.rs Port the #[linkage] attribute to the new attribute system 2025-08-13 21:01:37 +02:00
size_of_val.rs remove explicit deref of AbiAlign for most methods 2025-09-28 15:02:14 -07:00
target_features.rs Use rust rather than LLVM target features in the target spec 2025-11-25 14:39:42 +00:00