Skip to content

Commit ef7a780

Browse files
committed
add test for simd from array repeat codegen
1 parent 55407b8 commit ef7a780

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//@ add-minicore
2+
//@ revisions: X86 AARCH64 RISCV S390X
3+
//@ [X86] compile-flags: -Copt-level=3 --target=x86_64-unknown-linux-gnu
4+
//@ [X86] needs-llvm-components: x86
5+
//@ [AARCH64] compile-flags: -Copt-level=3 --target=aarch64-unknown-linux-gnu
6+
//@ [AARCH64] needs-llvm-components: aarch64
7+
//@ [RISCV] compile-flags: -Copt-level=3 --target riscv64gc-unknown-linux-gnu -Ctarget-feature=+v
8+
//@ [RISCV] needs-llvm-components: riscv
9+
//@ [S390X] compile-flags: -Copt-level=3 --target s390x-unknown-linux-gnu -Ctarget-feature=+vector
10+
//@ [S390X] needs-llvm-components: systemz
11+
#![crate_type = "lib"]
12+
#![feature(repr_simd)]
13+
#![feature(no_core)]
14+
#![no_std]
15+
#![no_core]
16+
extern crate minicore;
17+
use minicore::*;
18+
19+
#[repr(simd)]
20+
pub struct Simd<T, const N: usize>(pub [T; N]);
21+
22+
pub type u8x16 = Simd<u8, 16>;
23+
24+
// Regression test for https://github.com/rust-lang/rust/issues/97804.
25+
26+
#[unsafe(no_mangle)]
27+
fn foo(v: u16, p: &mut [u8; 16]) {
28+
// An array repeat transmuted into a SIMD type should emit a canonical LLVM splat sequence:
29+
//
30+
// CHECK-LABEL: foo
31+
// CHECK: start
32+
// CHECK-NEXT: %0 = insertelement <8 x i16> poison, i16 %v, i64 0
33+
// CHECK-NEXT: %1 = shufflevector <8 x i16> %0, <8 x i16> poison, <8 x i32> zeroinitializer
34+
// CHECK-NEXT: store <8 x i16> %1, ptr %p, align 1
35+
// CHECK-NEXT: ret void
36+
unsafe {
37+
let v: u8x16 = mem::transmute([v; 8]);
38+
*p = mem::transmute(v);
39+
}
40+
}

0 commit comments

Comments
 (0)