Skip to content

Commit 06ff86c

Browse files
committed
Add autocast tests
- Correct usage of invalid intrinsics in tests
1 parent 925028f commit 06ff86c

8 files changed

+188
-1
lines changed

tests/codegen/inject-autocast.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//@ compile-flags: -C opt-level=0
2+
//@ only-x86_64
3+
4+
#![feature(link_llvm_intrinsics, abi_unadjusted, repr_simd, simd_ffi, portable_simd, f16)]
5+
#![crate_type = "lib"]
6+
7+
use std::simd::{f32x4, i16x8, i64x2};
8+
9+
#[repr(simd)]
10+
pub struct Tile([i8; 1024]);
11+
12+
#[repr(C, packed)]
13+
pub struct Bar(u32, i64x2, i64x2, i64x2, i64x2, i64x2, i64x2);
14+
// CHECK: %Bar = type <{ i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> }>
15+
16+
#[repr(simd)]
17+
pub struct f16x8([f16; 8]);
18+
19+
// CHECK-LABEL: @amx_autocast
20+
#[no_mangle]
21+
pub unsafe fn amx_autocast(m: u16, n: u16, k: u16, a: Tile, b: Tile, c: Tile) -> Tile {
22+
extern "unadjusted" {
23+
#[link_name = "llvm.x86.tdpbuud.internal"]
24+
fn foo(m: u16, n: u16, k: u16, a: Tile, b: Tile, c: Tile) -> Tile;
25+
}
26+
27+
// CHECK: %3 = call x86_amx @llvm.x86.cast.vector.to.tile.v1024i8(<1024 x i8> %0)
28+
// CHECK-NEXT: %4 = call x86_amx @llvm.x86.cast.vector.to.tile.v1024i8(<1024 x i8> %1)
29+
// CHECK-NEXT: %5 = call x86_amx @llvm.x86.cast.vector.to.tile.v1024i8(<1024 x i8> %2)
30+
// CHECK-NEXT: %6 = call x86_amx @llvm.x86.tdpbuud.internal(i16 %m, i16 %n, i16 %k, x86_amx %3, x86_amx %4, x86_amx %5)
31+
// CHECK-NEXT: %7 = call <1024 x i8> @llvm.x86.cast.tile.to.vector.v1024i8(x86_amx %6)
32+
foo(m, n, k, a, b, c)
33+
}
34+
35+
// CHECK-LABEL: @struct_with_i1_vector_autocast
36+
#[no_mangle]
37+
pub unsafe fn struct_with_i1_vector_autocast(a: i64x2, b: i64x2) -> (u8, u8) {
38+
extern "unadjusted" {
39+
#[link_name = "llvm.x86.avx512.vp2intersect.q.128"]
40+
fn foo(a: i64x2, b: i64x2) -> (u8, u8);
41+
}
42+
43+
// CHECK: %2 = call { <2 x i1>, <2 x i1> } @llvm.x86.avx512.vp2intersect.q.128(<2 x i64> %0, <2 x i64> %1)
44+
// CHECK-NEXT: %3 = extractvalue { <2 x i1>, <2 x i1> } %2, 0
45+
// CHECK-NEXT: %4 = shufflevector <2 x i1> %3, <2 x i1> zeroinitializer, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 2, i32 3, i32 2, i32 3>
46+
// CHECK-NEXT: %5 = bitcast <8 x i1> %4 to i8
47+
// CHECK-NEXT: %6 = insertvalue { i8, i8 } poison, i8 %5, 0
48+
// CHECK-NEXT: %7 = extractvalue { <2 x i1>, <2 x i1> } %2, 1
49+
// CHECK-NEXT: %8 = shufflevector <2 x i1> %7, <2 x i1> zeroinitializer, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 2, i32 3, i32 2, i32 3>
50+
// CHECK-NEXT: %9 = bitcast <8 x i1> %8 to i8
51+
// CHECK-NEXT: %10 = insertvalue { i8, i8 } %6, i8 %9, 1
52+
foo(a, b)
53+
}
54+
55+
// CHECK-LABEL: @bf16_vector_autocast
56+
#[no_mangle]
57+
pub unsafe fn bf16_vector_autocast(a: f32x4) -> i16x8 {
58+
extern "unadjusted" {
59+
#[link_name = "llvm.x86.vcvtneps2bf16128"]
60+
fn foo(a: f32x4) -> i16x8;
61+
}
62+
63+
// CHECK: %1 = call <8 x bfloat> @llvm.x86.vcvtneps2bf16128(<4 x float> %0)
64+
// CHECK-NEXT: %2 = bitcast <8 x bfloat> %1 to <8 x i16>
65+
foo(a)
66+
}
67+
68+
// CHECK-LABEL: @struct_autocast
69+
#[no_mangle]
70+
pub unsafe fn struct_autocast(key_metadata: u32, key: i64x2) -> Bar {
71+
extern "unadjusted" {
72+
#[link_name = "llvm.x86.encodekey128"]
73+
fn foo(key_metadata: u32, key: i64x2) -> Bar;
74+
}
75+
76+
// CHECK: %1 = call { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } @llvm.x86.encodekey128(i32 %key_metadata, <2 x i64> %0)
77+
// CHECK-NEXT: %2 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %1, 0
78+
// CHECK-NEXT: %3 = insertvalue %Bar poison, i32 %2, 0
79+
// CHECK-NEXT: %4 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %1, 1
80+
// CHECK-NEXT: %5 = insertvalue %Bar %3, <2 x i64> %4, 1
81+
// CHECK-NEXT: %6 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %1, 2
82+
// CHECK-NEXT: %7 = insertvalue %Bar %5, <2 x i64> %6, 2
83+
// CHECK-NEXT: %8 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %1, 3
84+
// CHECK-NEXT: %9 = insertvalue %Bar %7, <2 x i64> %8, 3
85+
// CHECK-NEXT: %10 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %1, 4
86+
// CHECK-NEXT: %11 = insertvalue %Bar %9, <2 x i64> %10, 4
87+
// CHECK-NEXT: %12 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %1, 5
88+
// CHECK-NEXT: %13 = insertvalue %Bar %11, <2 x i64> %12, 5
89+
// CHECK-NEXT: %14 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %1, 6
90+
// CHECK-NEXT: %15 = insertvalue %Bar %13, <2 x i64> %14, 6
91+
foo(key_metadata, key)
92+
}
93+
94+
// CHECK-LABEL: @i1_vector_autocast
95+
#[no_mangle]
96+
pub unsafe fn i1_vector_autocast(a: f16x8) -> u8 {
97+
extern "unadjusted" {
98+
#[link_name = "llvm.x86.avx512fp16.fpclass.ph.128"]
99+
fn foo(a: f16x8, b: i32) -> u8;
100+
}
101+
102+
// CHECK: %1 = call <8 x i1> @llvm.x86.avx512fp16.fpclass.ph.128(<8 x half> %0, i32 1)
103+
// CHECK-NEXT: %_0 = bitcast <8 x i1> %1 to i8
104+
foo(a, 1)
105+
}
106+
107+
// CHECK: declare x86_amx @llvm.x86.tdpbuud.internal(i16, i16, i16, x86_amx, x86_amx, x86_amx)
108+
109+
// CHECK: declare x86_amx @llvm.x86.cast.vector.to.tile.v1024i8(<1024 x i8>)
110+
111+
// CHECK: declare <1024 x i8> @llvm.x86.cast.tile.to.vector.v1024i8(x86_amx)
112+
113+
// CHECK: declare { <2 x i1>, <2 x i1> } @llvm.x86.avx512.vp2intersect.q.128(<2 x i64>, <2 x i64>)
114+
115+
// CHECK: declare <8 x bfloat> @llvm.x86.vcvtneps2bf16128(<4 x float>)
116+
117+
// CHECK: declare { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } @llvm.x86.encodekey128(i32, <2 x i64>)
118+
119+
// CHECK: declare <8 x i1> @llvm.x86.avx512fp16.fpclass.ph.128(<8 x half>, i32 immarg)

tests/run-make/simd-ffi/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern "C" {
3535
fn integer(a: i32x4, b: i32x4) -> i32x4;
3636
// vmaxq_s32
3737
#[cfg(target_arch = "aarch64")]
38-
#[link_name = "llvm.aarch64.neon.maxs.v4i32"]
38+
#[link_name = "llvm.aarch64.neon.smax.v4i32"]
3939
fn integer(a: i32x4, b: i32x4) -> i32x4;
4040

4141
// Use a generic LLVM intrinsic to do type checking on other platforms
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@ add-core-stubs
2+
//@ build-pass
3+
//@ ignore-pass
4+
//@ compile-flags: --target aarch64-unknown-linux-gnu
5+
//@ needs-llvm-components: aarch64
6+
#![feature(no_core, lang_items, link_llvm_intrinsics, abi_unadjusted, repr_simd, simd_ffi)]
7+
#![no_std]
8+
#![no_core]
9+
#![allow(internal_features, non_camel_case_types, improper_ctypes)]
10+
#![crate_type = "lib"]
11+
12+
extern crate minicore;
13+
use minicore::*;
14+
15+
#[repr(simd)]
16+
pub struct i8x8([i8; 8]);
17+
18+
extern "unadjusted" {
19+
#[link_name = "llvm.aarch64.neon.rbit.v8i8"]
20+
fn foo(a: i8x8) -> i8x8;
21+
}
22+
23+
#[target_feature(enable = "neon")]
24+
pub unsafe fn bar(a: i8x8) -> i8x8 {
25+
foo(a)
26+
}
27+
28+
//~? NOTE: Using deprecated intrinsic `llvm.aarch64.neon.rbit.v8i8`, `llvm.bitreverse.v8i8` can be used instead
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
note: Using deprecated intrinsic `llvm.aarch64.neon.rbit.v8i8`, `llvm.bitreverse.v8i8` can be used instead
2+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ build-fail
2+
3+
#![feature(link_llvm_intrinsics, abi_unadjusted)]
4+
#![allow(internal_features, non_camel_case_types, improper_ctypes)]
5+
6+
extern "unadjusted" {
7+
#[link_name = "llvm.assume"]
8+
fn foo();
9+
}
10+
11+
pub fn main() {
12+
unsafe { foo() }
13+
}
14+
15+
//~? ERROR: Intrinsic signature mismatch for `llvm.assume`: expected signature `void (i1)`
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: Intrinsic signature mismatch for `llvm.assume`: expected signature `void (i1)`
2+
3+
error: aborting due to 1 previous error
4+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ build-fail
2+
3+
#![feature(link_llvm_intrinsics, abi_unadjusted)]
4+
#![allow(internal_features, non_camel_case_types, improper_ctypes)]
5+
6+
extern "unadjusted" {
7+
#[link_name = "llvm.abcde"]
8+
fn foo();
9+
}
10+
11+
pub fn main() {
12+
unsafe { foo() }
13+
}
14+
15+
//~? ERROR: Invalid LLVM intrinsic: `llvm.abcde`
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: Invalid LLVM intrinsic: `llvm.abcde`
2+
3+
error: aborting due to 1 previous error
4+

0 commit comments

Comments
 (0)