Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6b96a60

Browse files
committed
Add implied features to non-target-feature functions
1 parent 5006711 commit 6b96a60

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use libc::c_int;
88
use rustc_codegen_ssa::base::wants_wasm_eh;
99
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010
use rustc_data_structures::small_c_str::SmallCStr;
11+
use rustc_data_structures::unord::UnordSet;
1112
use rustc_fs_util::path_to_c_string;
1213
use rustc_middle::bug;
1314
use rustc_session::config::{PrintKind, PrintRequest};
@@ -553,11 +554,26 @@ pub(crate) fn global_llvm_features(
553554
let supported_features = sess.target.supported_target_features();
554555
let (llvm_major, _, _) = get_version();
555556
let mut featsmap = FxHashMap::default();
556-
let feats = sess
557-
.opts
558-
.cg
559-
.target_feature
560-
.split(',')
557+
558+
// insert implied features
559+
let mut all_rust_features = vec![];
560+
for feature in sess.opts.cg.target_feature.split(',') {
561+
match feature.strip_prefix('+') {
562+
Some(feature) => all_rust_features.extend(
563+
UnordSet::from(
564+
sess.target
565+
.implied_target_features(std::iter::once(Symbol::intern(feature))),
566+
)
567+
.to_sorted_stable_ord()
568+
.iter()
569+
.map(|s| format!("+{}", s.as_str())),
570+
),
571+
_ => all_rust_features.push(feature.to_string()),
572+
}
573+
}
574+
575+
let feats = all_rust_features
576+
.iter()
561577
.filter_map(|s| {
562578
let enable_disable = match s.chars().next() {
563579
None => return None,

tests/codegen/target-feature-overrides.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ revisions: COMPAT INCOMPAT
22
//@ needs-llvm-components: x86
33
//@ compile-flags: --target=x86_64-unknown-linux-gnu -Copt-level=3
4-
//@ [COMPAT] compile-flags: -Ctarget-feature=+avx2,+avx
4+
//@ [COMPAT] compile-flags: -Ctarget-feature=+avx2
55
//@ [INCOMPAT] compile-flags: -Ctarget-feature=-avx2,-avx
66

77
// See also tests/assembly/target-feature-multiple.rs
@@ -39,8 +39,8 @@ pub unsafe fn banana() -> u32 {
3939
}
4040

4141
// CHECK: attributes [[APPLEATTRS]]
42-
// COMPAT-SAME: "target-features"="+avx2,+avx,{{.*}}"
42+
// COMPAT-SAME: "target-features"="+avx,+avx2,{{.*}}"
4343
// INCOMPAT-SAME: "target-features"="-avx2,-avx,+avx,{{.*}}"
4444
// CHECK: attributes [[BANANAATTRS]]
45-
// COMPAT-SAME: "target-features"="+avx2,+avx,{{.*}}"
45+
// COMPAT-SAME: "target-features"="+avx,+avx2,{{.*}}"
4646
// INCOMPAT-SAME: "target-features"="-avx2,-avx"

tests/codegen/tied-features-strength.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// is LLVM-14 we can remove the optional regex matching for this feature.
99

1010
//@ [ENABLE_SVE] compile-flags: -C target-feature=+sve -Copt-level=0
11-
// ENABLE_SVE: attributes #0 = { {{.*}} "target-features"="{{((\+outline-atomics,?)|(\+v8a,?)?|(\+sve,?)|(\+neon,?))*}}" }
11+
// ENABLE_SVE: attributes #0 = { {{.*}} "target-features"="{{((\+outline-atomics,?)|(\+v8a,?)?|(\+sve,?)|(\+neon,?)|(\+fp-armv8,?))*}}" }
1212

1313
//@ [DISABLE_SVE] compile-flags: -C target-feature=-sve -Copt-level=0
1414
// DISABLE_SVE: attributes #0 = { {{.*}} "target-features"="{{((\+outline-atomics,?)|(\+v8a,?)?|(-sve,?)|(\+neon,?))*}}" }

0 commit comments

Comments
 (0)