Skip to content

Commit 70b7bed

Browse files
committed
Add autocast tests
- Correct usage of invalid intrinsics in tests
1 parent 95d66be commit 70b7bed

8 files changed

+163
-1
lines changed

tests/codegen/inject-autocast.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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(C, packed)]
10+
pub struct Bar(u32, i64x2, i64x2, i64x2, i64x2, i64x2, i64x2);
11+
// CHECK: %Bar = type <{ i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> }>
12+
13+
#[repr(simd)]
14+
pub struct f16x8([f16; 8]);
15+
16+
// CHECK-LABEL: @struct_with_i1_vector_autocast
17+
#[no_mangle]
18+
pub unsafe fn struct_with_i1_vector_autocast(a: i64x2, b: i64x2) -> (u8, u8) {
19+
extern "unadjusted" {
20+
#[link_name = "llvm.x86.avx512.vp2intersect.q.128"]
21+
fn foo(a: i64x2, b: i64x2) -> (u8, u8);
22+
}
23+
24+
// CHECK: %0 = call { <2 x i1>, <2 x i1> } @llvm.x86.avx512.vp2intersect.q.128(<2 x i64> %a, <2 x i64> %b)
25+
// CHECK-NEXT: %1 = extractvalue { <2 x i1>, <2 x i1> } %0, 0
26+
// CHECK-NEXT: %2 = shufflevector <2 x i1> %1, <2 x i1> zeroinitializer, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 2, i32 3, i32 2, i32 3>
27+
// CHECK-NEXT: %3 = bitcast <8 x i1> %2 to i8
28+
// CHECK-NEXT: %4 = insertvalue { i8, i8 } poison, i8 %3, 0
29+
// CHECK-NEXT: %5 = extractvalue { <2 x i1>, <2 x i1> } %0, 1
30+
// CHECK-NEXT: %6 = shufflevector <2 x i1> %5, <2 x i1> zeroinitializer, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 2, i32 3, i32 2, i32 3>
31+
// CHECK-NEXT: %7 = bitcast <8 x i1> %6 to i8
32+
// CHECK-NEXT: %8 = insertvalue { i8, i8 } %4, i8 %7, 1
33+
foo(a, b)
34+
}
35+
36+
// CHECK-LABEL: @bf16_vector_autocast
37+
#[no_mangle]
38+
pub unsafe fn bf16_vector_autocast(a: f32x4) -> i16x8 {
39+
extern "unadjusted" {
40+
#[link_name = "llvm.x86.vcvtneps2bf16128"]
41+
fn foo(a: f32x4) -> i16x8;
42+
}
43+
44+
// CHECK: %0 = call <8 x bfloat> @llvm.x86.vcvtneps2bf16128(<4 x float> %a)
45+
// CHECK-NEXT: %_0 = bitcast <8 x bfloat> %0 to <8 x i16>
46+
foo(a)
47+
}
48+
49+
// CHECK-LABEL: @struct_autocast
50+
#[no_mangle]
51+
pub unsafe fn struct_autocast(key_metadata: u32, key: i64x2) -> Bar {
52+
extern "unadjusted" {
53+
#[link_name = "llvm.x86.encodekey128"]
54+
fn foo(key_metadata: u32, key: i64x2) -> Bar;
55+
}
56+
57+
// CHECK: %0 = 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> %key)
58+
// CHECK-NEXT: %1 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %0, 0
59+
// CHECK-NEXT: %2 = insertvalue %Bar poison, i32 %1, 0
60+
// CHECK-NEXT: %3 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %0, 1
61+
// CHECK-NEXT: %4 = insertvalue %Bar %2, <2 x i64> %3, 1
62+
// CHECK-NEXT: %5 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %0, 2
63+
// CHECK-NEXT: %6 = insertvalue %Bar %4, <2 x i64> %5, 2
64+
// CHECK-NEXT: %7 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %0, 3
65+
// CHECK-NEXT: %8 = insertvalue %Bar %6, <2 x i64> %7, 3
66+
// CHECK-NEXT: %9 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %0, 4
67+
// CHECK-NEXT: %10 = insertvalue %Bar %8, <2 x i64> %9, 4
68+
// CHECK-NEXT: %11 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %0, 5
69+
// CHECK-NEXT: %12 = insertvalue %Bar %10, <2 x i64> %11, 5
70+
// CHECK-NEXT: %13 = extractvalue { i32, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } %0, 6
71+
// CHECK-NEXT: %14 = insertvalue %Bar %12, <2 x i64> %13, 6
72+
foo(key_metadata, key)
73+
}
74+
75+
// CHECK-LABEL: @i1_vector_autocast
76+
#[no_mangle]
77+
pub unsafe fn i1_vector_autocast(a: f16x8) -> u8 {
78+
extern "unadjusted" {
79+
#[link_name = "llvm.x86.avx512fp16.fpclass.ph.128"]
80+
fn foo(a: f16x8, b: i32) -> u8;
81+
}
82+
83+
// CHECK: %0 = call <8 x i1> @llvm.x86.avx512fp16.fpclass.ph.128(<8 x half> %a, i32 1)
84+
// CHECK-NEXT: %_0 = bitcast <8 x i1> %0 to i8
85+
foo(a, 1)
86+
}
87+
88+
// CHECK: declare { <2 x i1>, <2 x i1> } @llvm.x86.avx512.vp2intersect.q.128(<2 x i64>, <2 x i64>)
89+
90+
// CHECK: declare <8 x bfloat> @llvm.x86.vcvtneps2bf16128(<4 x float>)
91+
92+
// 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>)
93+
94+
// 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)