rust/tests/ui/simd/intrinsic
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
..
float-math-pass.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
float-minmax-pass.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
generic-arithmetic-2.rs Ignore more failing ui tests for GCC backend 2025-09-26 15:33:48 +02:00
generic-arithmetic-2.stderr Ignore more failing ui tests for GCC backend 2025-09-26 15:33:48 +02:00
generic-arithmetic-pass.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
generic-arithmetic-saturating-2.rs remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
generic-arithmetic-saturating-2.stderr remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
generic-arithmetic-saturating-pass.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
generic-as.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
generic-bitmask-pass.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
generic-bitmask.rs remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
generic-bitmask.stderr remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
generic-bswap-byte.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
generic-cast-pass.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
generic-cast-pointer-width.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
generic-cast.rs remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
generic-cast.stderr remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
generic-comparison-pass.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
generic-comparison.rs remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
generic-comparison.stderr remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
generic-elements-pass.rs make simd_insert_dyn and simd_extract_dyn const 2026-01-21 14:57:33 +01:00
generic-elements.rs Ignore more failing ui tests for GCC backend 2025-09-26 15:33:48 +02:00
generic-elements.stderr Ignore more failing ui tests for GCC backend 2025-09-26 15:33:48 +02:00
generic-gather-scatter-pass.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
generic-gather-scatter.rs simd intrinsics with mask: accept unsigned integer masks 2025-04-20 12:25:27 +02:00
generic-gather-scatter.stderr simd intrinsics with mask: accept unsigned integer masks 2025-04-20 12:25:27 +02:00
generic-reduction-pass.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
generic-reduction.rs simplify some imports with simd::* 2025-02-27 12:22:59 +01:00
generic-reduction.stderr make simd_insert and simd_extract const fns 2025-02-27 12:23:00 +01:00
generic-select-pass.rs Enable const-testing for the ported SIMD intrinsics 2025-11-17 20:10:14 +05:30
generic-select.rs simd intrinsics with mask: accept unsigned integer masks 2025-04-20 12:25:27 +02:00
generic-select.stderr simd intrinsics with mask: accept unsigned integer masks 2025-04-20 12:25:27 +02:00
generic-shuffle.rs remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
generic-shuffle.stderr remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
inlining-issue67557-ice.rs remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
inlining-issue67557.rs So many test updates x_x 2025-07-20 10:15:14 -07:00
issue-85855.rs remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
issue-85855.stderr remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
ptr-cast.rs So many test updates x_x 2025-07-20 10:15:14 -07:00
splat.rs const-eval: do not call immediate_const_vector on vector of pointers 2026-01-24 10:40:47 +01:00