Skip to content

Commit cdb9de7

Browse files
committed
Add codegen test ensuring always-inline closures don't bypass target features
1 parent ddb16e2 commit cdb9de7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// only-x86_64
2+
// compile-flags: -Copt-level=3
3+
4+
#![crate_type = "lib"]
5+
#![feature(target_feature_11)]
6+
7+
#[cfg(target_arch = "x86_64")]
8+
use std::arch::x86_64::*;
9+
10+
// CHECK-LABEL: @with_avx
11+
#[no_mangle]
12+
#[cfg(target_arch = "x86_64")]
13+
#[target_feature(enable = "avx")]
14+
fn with_avx(x: __m256) -> __m256 {
15+
// CHECK: fadd
16+
let add = {
17+
#[inline(always)]
18+
|x, y| unsafe { _mm256_add_ps(x, y) }
19+
};
20+
add(x, x)
21+
}
22+
23+
// CHECK-LABEL: @without_avx
24+
#[no_mangle]
25+
#[cfg(target_arch = "x86_64")]
26+
unsafe fn without_avx(x: __m256) -> __m256 {
27+
// CHECK-NOT: fadd
28+
let add = {
29+
#[inline(always)]
30+
|x, y| unsafe { _mm256_add_ps(x, y) }
31+
};
32+
add(x, x)
33+
}

0 commit comments

Comments
 (0)