Skip to content

Commit ef34bce

Browse files
committed
Update and create new tests
1 parent df654be commit ef34bce

9 files changed

Lines changed: 271 additions & 2 deletions
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ add-minicore
2+
//@ compile-flags: --target x86_64-unknown-linux-gnu -C target-feature=+avx512f -Zinline-mir=no -C no-prepopulate-passes
3+
//@ needs-llvm-components: x86
4+
5+
#![crate_type = "lib"]
6+
#![feature(no_core, lang_items, target_feature_inline_always)]
7+
#![no_core]
8+
9+
extern crate minicore;
10+
use minicore::*;
11+
12+
#[inline(always)]
13+
#[target_feature(enable = "sse")]
14+
#[no_mangle]
15+
pub unsafe fn single_target_feature() -> i32 {
16+
42
17+
}
18+
19+
// `avx512f` is enough here because it implicitly enables `avx`, which in turn
20+
// implies `sse`. That makes the caller compatible with the callee at this
21+
// callsite, so the `alwaysinline` attribute should be emitted on the call.
22+
#[no_mangle]
23+
// CHECK-LABEL: define{{( noundef)?}} i32 @inherits_from_global() unnamed_addr
24+
pub fn inherits_from_global() -> i32 {
25+
unsafe {
26+
// CHECK: %_0 = call{{( noundef)?}} i32 @single_target_feature() [[CALL_ATTRS:#[0-9]+]]
27+
single_target_feature()
28+
}
29+
}
30+
31+
// CHECK: attributes [[CALL_ATTRS]] = { alwaysinline nounwind }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ build-pass
2+
//@ compile-flags: --crate-type=lib --target=x86_64-unknown-linux-gnu
3+
//@ needs-llvm-components: x86
4+
//@ ignore-backends: gcc
5+
6+
#![feature(target_feature_inline_always)]
7+
#![allow(dead_code, unused_unsafe)]
8+
9+
use std::arch::x86_64::__m256;
10+
11+
#[inline(never)]
12+
#[target_feature(enable = "sse")]
13+
fn sink(_x: &__m256) {}
14+
15+
#[inline(always)]
16+
#[target_feature(enable = "sse")]
17+
fn callee_missing_avx512f(x: &__m256, y: bool) {
18+
if y {
19+
callee_missing_avx512f(x, y);
20+
} else {
21+
sink(x);
22+
}
23+
}
24+
25+
// `avx512f` only changes the `__m256` ABI because it implicitly enables `avx`.
26+
#[target_feature(enable = "avx512f")]
27+
fn caller_has_avx512f_abi_mismatch(x: &__m256, y: bool) {
28+
unsafe { callee_missing_avx512f(x, y) }
29+
//~^ WARNING call to `#[inline(always)]`-annotated `callee_missing_avx512f` requires the same target features to be inlined [inline_always_mismatching_target_features]
30+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
warning: call to `#[inline(always)]`-annotated `callee_missing_avx512f` requires the same target features to be inlined
2+
--> $DIR/inline-always-vector-abi-avx512f.rs:28:14
3+
|
4+
LL | unsafe { callee_missing_avx512f(x, y) }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: function will not be inlined
8+
= note: the following target features are on `caller_has_avx512f_abi_mismatch` but missing from `callee_missing_avx512f`: avx512f
9+
note: `caller_has_avx512f_abi_mismatch` is defined here
10+
--> $DIR/inline-always-vector-abi-avx512f.rs:27:1
11+
|
12+
LL | fn caller_has_avx512f_abi_mismatch(x: &__m256, y: bool) {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
= note: `#[warn(inline_always_mismatching_target_features)]` on by default
15+
help: add `#[target_feature]` attribute to `callee_missing_avx512f`
16+
|
17+
LL + #[target_feature(enable = "avx512f")]
18+
LL | fn callee_missing_avx512f(x: &__m256, y: bool) {
19+
|
20+
21+
warning: 1 warning emitted
22+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//@ run-pass
2+
//@ compile-flags: -C opt-level=3
3+
//@ only-x86_64
4+
//@ only-linux
5+
//@ ignore-backends: gcc
6+
7+
#![feature(target_feature_inline_always)]
8+
9+
use std::arch::x86_64::__m256;
10+
11+
#[inline(never)]
12+
#[target_feature(enable = "sse")]
13+
fn f(x: &__m256) {
14+
let x = unsafe { std::mem::transmute::<_, [u32; 8]>(*x) };
15+
assert_eq!(x, [1, 2, 3, 4, 5, 6, 7, 8]);
16+
}
17+
18+
#[inline(always)]
19+
#[target_feature(enable = "sse")]
20+
fn g(x: &__m256, y: bool) {
21+
if y {
22+
g(x, y);
23+
} else {
24+
f(x);
25+
}
26+
}
27+
28+
#[target_feature(enable = "avx")]
29+
fn h(x: &__m256, y: bool) {
30+
g(x, y)
31+
//~^ WARNING call to `#[inline(always)]`-annotated `g` requires the same target features to be inlined [inline_always_mismatching_target_features]
32+
}
33+
34+
fn main() {
35+
if !is_x86_feature_detected!("avx") {
36+
return;
37+
}
38+
39+
let x = std::hint::black_box(unsafe {
40+
std::mem::transmute::<_, __m256>([1_u32, 2, 3, 4, 5, 6, 7, 8])
41+
});
42+
let y = std::hint::black_box(false);
43+
unsafe { h(&x, y) }
44+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
warning: call to `#[inline(always)]`-annotated `g` requires the same target features to be inlined
2+
--> $DIR/inline-always-vector-abi-callee-missing.rs:31:5
3+
|
4+
LL | g(x, y)
5+
| ^^^^^^^
6+
|
7+
= note: function will not be inlined
8+
= note: the following target features are on `h` but missing from `g`: avx
9+
note: `h` is defined here
10+
--> $DIR/inline-always-vector-abi-callee-missing.rs:30:1
11+
|
12+
LL | fn h(x: &__m256, y: bool) {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+
= note: `#[warn(inline_always_mismatching_target_features)]` on by default
15+
help: add `#[target_feature]` attribute to `g`
16+
|
17+
LL + #[target_feature(enable = "avx")]
18+
LL | fn g(x: &__m256, y: bool) {
19+
|
20+
21+
warning: 1 warning emitted
22+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//@ run-pass
2+
//@ compile-flags: -C opt-level=3 -Ctarget-feature=+avx
3+
//@ only-x86_64
4+
//@ only-linux
5+
//@ ignore-backends: gcc
6+
7+
#![feature(target_feature_inline_always)]
8+
9+
use std::arch::x86_64::__m256;
10+
11+
const EXPECTED: [u32; 8] = [1, 2, 3, 4, 5, 6, 7, 8];
12+
13+
#[inline(never)]
14+
#[target_feature(enable = "sse")]
15+
fn f(x: &__m256) {
16+
let x = unsafe { std::mem::transmute::<_, [u32; 8]>(*x) };
17+
assert_eq!(x, EXPECTED);
18+
}
19+
20+
#[inline(always)]
21+
#[target_feature(enable = "sse")]
22+
fn g(x: &__m256) {
23+
f(x);
24+
}
25+
26+
#[target_feature(enable = "avx")]
27+
fn h(x: &__m256) {
28+
g(x);
29+
}
30+
31+
fn main() {
32+
let x = std::hint::black_box(unsafe { std::mem::transmute::<_, __m256>(EXPECTED) });
33+
unsafe { h(&x); }
34+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//@ build-pass
2+
//@ compile-flags: --crate-type=lib --target=x86_64-unknown-linux-gnu
3+
//@ needs-llvm-components: x86
4+
//@ ignore-backends: gcc
5+
6+
#![feature(target_feature_inline_always)]
7+
#![allow(dead_code, unused_unsafe)]
8+
9+
use std::arch::x86_64::__m256;
10+
11+
#[inline(never)]
12+
#[target_feature(enable = "sse")]
13+
fn sink(_x: &__m256) {}
14+
15+
#[inline(always)]
16+
#[target_feature(enable = "sse")]
17+
fn callee_missing_avx(x: &__m256, y: bool) {
18+
if y {
19+
callee_missing_avx(x, y);
20+
} else {
21+
sink(x);
22+
}
23+
}
24+
25+
#[target_feature(enable = "avx")]
26+
fn caller_has_abi_mismatch(x: &__m256, y: bool) {
27+
unsafe { callee_missing_avx(x, y) }
28+
//~^ WARNING call to `#[inline(always)]`-annotated `callee_missing_avx` requires the same target features to be inlined [inline_always_mismatching_target_features]
29+
}
30+
31+
#[inline(always)]
32+
#[target_feature(enable = "avx")]
33+
fn callee_requires_avx(x: &__m256, y: bool) {
34+
if y {
35+
callee_requires_avx(x, y);
36+
} else {
37+
sink(x);
38+
}
39+
}
40+
41+
#[target_feature(enable = "sse")]
42+
fn caller_missing_avx(x: &__m256, y: bool) {
43+
unsafe { callee_requires_avx(x, y) }
44+
//~^ WARNING call to `#[inline(always)]`-annotated `callee_requires_avx` requires the same target features to be inlined [inline_always_mismatching_target_features]
45+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
warning: call to `#[inline(always)]`-annotated `callee_missing_avx` requires the same target features to be inlined
2+
--> $DIR/inline-always-vector-abi.rs:27:14
3+
|
4+
LL | unsafe { callee_missing_avx(x, y) }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: function will not be inlined
8+
= note: the following target features are on `caller_has_abi_mismatch` but missing from `callee_missing_avx`: avx
9+
note: `caller_has_abi_mismatch` is defined here
10+
--> $DIR/inline-always-vector-abi.rs:26:1
11+
|
12+
LL | fn caller_has_abi_mismatch(x: &__m256, y: bool) {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
= note: `#[warn(inline_always_mismatching_target_features)]` on by default
15+
help: add `#[target_feature]` attribute to `callee_missing_avx`
16+
|
17+
LL + #[target_feature(enable = "avx")]
18+
LL | fn callee_missing_avx(x: &__m256, y: bool) {
19+
|
20+
21+
warning: call to `#[inline(always)]`-annotated `callee_requires_avx` requires the same target features to be inlined
22+
--> $DIR/inline-always-vector-abi.rs:43:14
23+
|
24+
LL | unsafe { callee_requires_avx(x, y) }
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
26+
|
27+
= note: function will not be inlined
28+
= note: the following target features are on `callee_requires_avx` but missing from `caller_missing_avx`: avx
29+
note: `callee_requires_avx` is defined here
30+
--> $DIR/inline-always-vector-abi.rs:33:1
31+
|
32+
LL | fn callee_requires_avx(x: &__m256, y: bool) {
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
help: add `#[target_feature]` attribute to `caller_missing_avx`
35+
|
36+
LL + #[target_feature(enable = "avx")]
37+
LL | fn caller_missing_avx(x: &__m256, y: bool) {
38+
|
39+
40+
warning: 2 warnings emitted
41+

tests/ui/target-feature/inline-always.aarch64.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | target_feature_identity();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: function will not be inlined
8-
= note: the following target features are on `target_feature_identity` but missing from `call_no_target_features`: neon, fp16
8+
= note: the following target features are on `target_feature_identity` but missing from `call_no_target_features`: fp16
99
note: `target_feature_identity` is defined here
1010
--> $DIR/inline-always.rs:17:1
1111
|
@@ -14,7 +14,7 @@ LL | pub unsafe fn target_feature_identity() {}
1414
= note: `#[warn(inline_always_mismatching_target_features)]` on by default
1515
help: add `#[target_feature]` attribute to `call_no_target_features`
1616
|
17-
LL + #[target_feature(enable = "neon,fp16")]
17+
LL + #[target_feature(enable = "fp16")]
1818
LL | unsafe fn call_no_target_features() {
1919
|
2020

0 commit comments

Comments
 (0)