diff options
| author | bors <bors@rust-lang.org> | 2021-03-17 05:46:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-03-17 05:46:08 +0000 |
| commit | 0c341226ad3780c11b1f29f6da8172b1d653f9ef (patch) | |
| tree | 162d827decc1efff2f30628bed859f092890ef44 /src/test/codegen | |
| parent | e655fb62216b6ba64a094b30f116d7988d19322d (diff) | |
| parent | 72fb4379d56b93b9bd0149649a74fb4b5465ec18 (diff) | |
| download | rust-0c341226ad3780c11b1f29f6da8172b1d653f9ef.tar.gz rust-0c341226ad3780c11b1f29f6da8172b1d653f9ef.zip | |
Auto merge of #83084 - nagisa:nagisa/features-native, r=petrochenkov
Adjust `-Ctarget-cpu=native` handling in cg_llvm When cg_llvm encounters the `-Ctarget-cpu=native` it computes an explciit set of features that applies to the target in order to correctly compile code for the host CPU (because e.g. `skylake` alone is not sufficient to tell if some of the instructions are available or not). However there were a couple of issues with how we did this. Firstly, the order in which features were overriden wasn't quite right – conceptually you'd expect `-Ctarget-cpu=native` option to override the features that are implicitly set by the target definition. However due to how other `-Ctarget-cpu` values are handled we must adopt the following order of priority: * Features from -Ctarget-cpu=*; are overriden by * Features implied by --target; are overriden by * Features from -Ctarget-feature; are overriden by * function specific features. Another problem was in that the function level `target-features` attribute would overwrite the entire set of the globally enabled features, rather than just the features the `#[target_feature(enable/disable)]` specified. With something like `-Ctarget-cpu=native` we'd end up in a situation wherein a function without `#[target_feature(enable)]` annotation would have a broader set of features compared to a function with one such attribute. This turned out to be a cause of heavy run-time regressions in some code using these function-level attributes in conjunction with `-Ctarget-cpu=native`, for example. With this PR rustc is more careful about specifying the entire set of features for functions that use `#[target_feature(enable/disable)]` or `#[instruction_set]` attributes. Sadly testing the original reproducer for this behaviour is quite impossible – we cannot rely on `-Ctarget-cpu=native` to be anything in particular on developer or CI machines. cc https://github.com/rust-lang/rust/issues/83027 `@BurntSushi`
Diffstat (limited to 'src/test/codegen')
| -rw-r--r-- | src/test/codegen/target-feature-multiple.rs | 9 | ||||
| -rw-r--r-- | src/test/codegen/target-feature-on-functions.rs | 9 | ||||
| -rw-r--r-- | src/test/codegen/target-feature-overrides.rs | 47 |
3 files changed, 47 insertions, 18 deletions
diff --git a/src/test/codegen/target-feature-multiple.rs b/src/test/codegen/target-feature-multiple.rs deleted file mode 100644 index f71a9c3c582..00000000000 --- a/src/test/codegen/target-feature-multiple.rs +++ /dev/null @@ -1,9 +0,0 @@ -// only-x86_64 -// compile-flags: -C target-feature=+sse2,-avx,+avx2 -C target-feature=+avx,-avx2 - -#![crate_type = "lib"] - -#[no_mangle] -pub fn foo() { - // CHECK: attributes #0 = { {{.*}}"target-features"="+sse2,-avx,+avx2,+avx,-avx2"{{.*}} } -} diff --git a/src/test/codegen/target-feature-on-functions.rs b/src/test/codegen/target-feature-on-functions.rs deleted file mode 100644 index d4d39d08b1e..00000000000 --- a/src/test/codegen/target-feature-on-functions.rs +++ /dev/null @@ -1,9 +0,0 @@ -// only-x86_64 -// compile-flags: -C target-feature=+avx - -#![crate_type = "lib"] - -#[no_mangle] -pub fn foo() { - // CHECK: attributes #0 = { {{.*}}"target-features"="+avx"{{.*}} } -} diff --git a/src/test/codegen/target-feature-overrides.rs b/src/test/codegen/target-feature-overrides.rs new file mode 100644 index 00000000000..2c19cfd8c22 --- /dev/null +++ b/src/test/codegen/target-feature-overrides.rs @@ -0,0 +1,47 @@ +// revisions: COMPAT INCOMPAT +// needs-llvm-components: x86 +// compile-flags: --target=x86_64-unknown-linux-gnu -Copt-level=3 +// [COMPAT] compile-flags: -Ctarget-feature=+avx2,+avx +// [INCOMPAT] compile-flags: -Ctarget-feature=-avx2,-avx + +// See also src/test/assembly/target-feature-multiple.rs +#![feature(no_core, lang_items)] +#![crate_type = "lib"] +#![no_core] + + +#[lang = "sized"] +trait Sized {} +#[lang = "copy"] +trait Copy {} + +extern "C" { + fn peach() -> u32; +} + +#[inline] +#[target_feature(enable = "avx")] +#[no_mangle] +pub unsafe fn apple() -> u32 { +// CHECK-LABEL: @apple() +// CHECK-SAME: [[APPLEATTRS:#[0-9]+]] { +// CHECK: {{.*}}call{{.*}}@peach + peach() +} + +// target features same as global (not reflected or overriden in IR) +#[no_mangle] +pub unsafe fn banana() -> u32 { +// CHECK-LABEL: @banana() +// CHECK-SAME: [[BANANAATTRS:#[0-9]+]] { +// COMPAT: {{.*}}call{{.*}}@peach +// INCOMPAT: {{.*}}call{{.*}}@apple + apple() // Compatible for inline in COMPAT revision and can't be inlined in INCOMPAT +} + +// CHECK: attributes [[APPLEATTRS]] +// COMPAT-SAME: "target-features"="+avx2,+avx,+avx" +// INCOMPAT-SAME: "target-features"="-avx2,-avx,+avx" +// CHECK: attributes [[BANANAATTRS]] +// CHECK-NOT: target-features +// CHECK-SAME: } |
