-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add implied target features to target_feature attribute #128221
Conversation
This comment has been minimized.
This comment has been minimized.
Can you also make this work with |
As far as I can tell, this change fixes that as well. I added the test from the linked issue and fixed the other failing tests, too |
2b4d881
to
ef90290
Compare
This comment has been minimized.
This comment has been minimized.
I'm not thrilled with the changes necessary to tests/codegen/target-feature-overrides.rs, I needed to add additional |
This comment has been minimized.
This comment has been minimized.
I had to add a much simpler version of this in #117468. In #117468's case it should be fixed in LLVM v19 I believe, but maybe it would encounter the same problem with inlining as well. |
I'm not sure about the merge order, but I can add the |
This comment has been minimized.
This comment has been minimized.
Thanks! |
The Miri subtree was changed cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
@@ -407,6 +407,79 @@ const IBMZ_ALLOWED_FEATURES: &[(&str, Stability)] = &[ | |||
// tidy-alphabetical-end | |||
]; | |||
|
|||
const X86_IMPLIED_FEATURES: &[(&str, &[&str])] = &[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to have this list here?
So far, we handle implied target features by having LLVM compute the full list of target features. That way, -C target-feature=avx2
makes cfg!(target_feature="avx")
be true -- at least that is my understanding.
We shouldn't have two different implied-target-feature mechanisms: either everything should use LLVM, or everything should use this table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seemed to be some desire in zulip to keep it separate, but I can do that (if I can find where cfg
is set from LLVM...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where on Zulip is that desire expressed? All I can see i Amanieu saying we should have our own implication table, but I don't see anyone even talking about the concern that different parts of rustc would have different user-visible notions of "implied target features".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should handle implied target features entirely on the rustc side and only use LLVM to query target features when -C target-cpu
is used (at least until we have our own mechanism for that). I want to move away from LLVM's target feature and into something that is backend-agnostic.
02f6b8e
to
b57dd4f
Compare
It would seem really strange to me if |
Given that this makes more code compile on stable, we probably should involve t-lang here before landing anything. |
In retrospect, I think this is due to #128426 as well. I don't think this is even necessarily fixed by switching the tables to LLVM, since LLVM definitely enables sse4.2 for avx |
This comment has been minimized.
This comment has been minimized.
Some changes occurred in compiler/rustc_codegen_gcc |
This comment has been minimized.
This comment has been minimized.
f0c7d4b
to
fe10ed8
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
Co-authored-by: Amanieu d'Antras <[email protected]>
4fad881
to
8818c95
Compare
@bors r=Amanieu |
…res, r=Amanieu Add implied target features to target_feature attribute See [zulip](https://rust-lang.zulipchat.com/#narrow/stream/208962-t-libs.2Fstdarch/topic/Why.20would.20target-feature.20include.20implied.20features.3F) for some context. Adds implied target features, e.g. `#[target_feature(enable = "avx2")]` acts like `#[target_feature(enable = "avx2,avx,sse4.2,sse4.1...")]`. Fixes rust-lang#128125, fixes rust-lang#128426 The implied feature sets are taken from [the rust reference](https://doc.rust-lang.org/reference/attributes/codegen.html?highlight=target-fea#x86-or-x86_64), there are certainly more features and targets to add. Please feel free to reassign this to whoever should review it. r? `@Amanieu`
…res, r=Amanieu Add implied target features to target_feature attribute See [zulip](https://rust-lang.zulipchat.com/#narrow/stream/208962-t-libs.2Fstdarch/topic/Why.20would.20target-feature.20include.20implied.20features.3F) for some context. Adds implied target features, e.g. `#[target_feature(enable = "avx2")]` acts like `#[target_feature(enable = "avx2,avx,sse4.2,sse4.1...")]`. Fixes rust-lang#128125, fixes rust-lang#128426 The implied feature sets are taken from [the rust reference](https://doc.rust-lang.org/reference/attributes/codegen.html?highlight=target-fea#x86-or-x86_64), there are certainly more features and targets to add. Please feel free to reassign this to whoever should review it. r? `@Amanieu`
Rollup of 7 pull requests Successful merges: - rust-lang#128206 (Make create_dll_import_lib easier to implement) - rust-lang#128221 (Add implied target features to target_feature attribute) - rust-lang#128384 (Add tests to ensure MTE tags are preserved across FFI boundaries) - rust-lang#128656 (Enable msvc for run-make/rust-lld) - rust-lang#128691 (Update `compiler-builtins` to 0.1.117) - rust-lang#128700 (Migrate `simd-ffi` `run-make` test to rmake) - rust-lang#128758 (Specify a minimum supported version for VxWorks) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#128221 (Add implied target features to target_feature attribute) - rust-lang#128261 (impl `Default` for collection iterators that don't already have it) - rust-lang#128353 (Change generate-copyright to generate HTML, with cargo dependencies included) - rust-lang#128679 (codegen: better centralize function declaration attribute computation) - rust-lang#128732 (make `import.vis` is immutable) - rust-lang#128755 (Integrate crlf directly into related test file instead via of .gitattributes) - rust-lang#128772 (rustc_codegen_ssa: Set architecture for object crate for 32-bit SPARC) - rust-lang#128782 (unused_parens: do not lint against parens around &raw) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#128221 - calebzulawski:implied-target-features, r=Amanieu Add implied target features to target_feature attribute See [zulip](https://rust-lang.zulipchat.com/#narrow/stream/208962-t-libs.2Fstdarch/topic/Why.20would.20target-feature.20include.20implied.20features.3F) for some context. Adds implied target features, e.g. `#[target_feature(enable = "avx2")]` acts like `#[target_feature(enable = "avx2,avx,sse4.2,sse4.1...")]`. Fixes rust-lang#128125, fixes rust-lang#128426 The implied feature sets are taken from [the rust reference](https://doc.rust-lang.org/reference/attributes/codegen.html?highlight=target-fea#x86-or-x86_64), there are certainly more features and targets to add. Please feel free to reassign this to whoever should review it. r? ``@Amanieu``
} | ||
} | ||
true | ||
RUSTC_SPECIAL_FEATURES.contains(feature) || features.contains(&Symbol::intern(feature)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line makes it so that the RUSTC_SPECIAL_FEATURES are always enabled in cfg, i.e. cfg!(target_feature = "backchain")
will always be true. Is that the intended behavior? It seems surprising, and there's no comment explaining the surprise.
It seems like that was also already the behavior before this PR. But it still seems odd...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I originally omitted this and tests failed, I didn't look into why this is done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a mistake originating in #127506.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed an issue for this: #129927
@@ -308,30 +277,61 @@ pub fn check_tied_features( | |||
/// Used to generate cfg variables and apply features | |||
/// Must express features in the way Rust understands them | |||
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a very similar function in compiler/rustc_codegen_gcc/src/lib.rs
which now works quite differently from its LLVM counterpart...
Cc @rust-lang/wg-gcc-backend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I plan at some point to try to remove duplications between the 2 codegens.
Enabling a tied feature should not enable the other feature automatically. This was fixed by something in rust-lang#128796, probably rust-lang#128221 or rust-lang#128679.
Enabling a tied feature should not enable the other feature automatically. This was fixed by something in rust-lang#128796, probably rust-lang#128221 or rust-lang#128679.
Enabling a tied feature should not enable the other feature automatically. This was fixed by something in rust-lang#128796, probably rust-lang#128221 or rust-lang#128679.
…n, r=wesleywiser codegen_ssa: consolidate tied target checks Fixes rust-lang#105110. Fixes rust-lang#105111. `rustc_codegen_llvm` and `rustc_codegen_gcc` duplicated logic for checking if tied target features were partially enabled. This PR consolidates these checks into `rustc_codegen_ssa` in the `codegen_fn_attrs` query, which also is run pre-monomorphisation for each function, which ensures that this check is run for unused functions, as would be expected. Also adds a test confirming that enabling one tied feature doesn't imply another - the appropriate error for this was already being emitted. I did a bisect and narrowed it down to two patches it was likely to be - something in rust-lang#128796, probably rust-lang#128221 or rust-lang#128679.
…n, r=wesleywiser codegen_ssa: consolidate tied target checks Fixes rust-lang#105110. Fixes rust-lang#105111. `rustc_codegen_llvm` and `rustc_codegen_gcc` duplicated logic for checking if tied target features were partially enabled. This PR consolidates these checks into `rustc_codegen_ssa` in the `codegen_fn_attrs` query, which also is run pre-monomorphisation for each function, which ensures that this check is run for unused functions, as would be expected. Also adds a test confirming that enabling one tied feature doesn't imply another - the appropriate error for this was already being emitted. I did a bisect and narrowed it down to two patches it was likely to be - something in rust-lang#128796, probably rust-lang#128221 or rust-lang#128679.
…n, r=wesleywiser codegen_ssa: consolidate tied target checks Fixes rust-lang#105110. Fixes rust-lang#105111. `rustc_codegen_llvm` and `rustc_codegen_gcc` duplicated logic for checking if tied target features were partially enabled. This PR consolidates these checks into `rustc_codegen_ssa` in the `codegen_fn_attrs` query, which also is run pre-monomorphisation for each function, which ensures that this check is run for unused functions, as would be expected. Also adds a test confirming that enabling one tied feature doesn't imply another - the appropriate error for this was already being emitted. I did a bisect and narrowed it down to two patches it was likely to be - something in rust-lang#128796, probably rust-lang#128221 or rust-lang#128679.
…n, r=wesleywiser codegen_ssa: consolidate tied target checks Fixes rust-lang#105110. Fixes rust-lang#105111. `rustc_codegen_llvm` and `rustc_codegen_gcc` duplicated logic for checking if tied target features were partially enabled. This PR consolidates these checks into `rustc_codegen_ssa` in the `codegen_fn_attrs` query, which also is run pre-monomorphisation for each function, which ensures that this check is run for unused functions, as would be expected. Also adds a test confirming that enabling one tied feature doesn't imply another - the appropriate error for this was already being emitted. I did a bisect and narrowed it down to two patches it was likely to be - something in rust-lang#128796, probably rust-lang#128221 or rust-lang#128679.
Rollup merge of rust-lang#130308 - davidtwco:tied-target-consolidation, r=wesleywiser codegen_ssa: consolidate tied target checks Fixes rust-lang#105110. Fixes rust-lang#105111. `rustc_codegen_llvm` and `rustc_codegen_gcc` duplicated logic for checking if tied target features were partially enabled. This PR consolidates these checks into `rustc_codegen_ssa` in the `codegen_fn_attrs` query, which also is run pre-monomorphisation for each function, which ensures that this check is run for unused functions, as would be expected. Also adds a test confirming that enabling one tied feature doesn't imply another - the appropriate error for this was already being emitted. I did a bisect and narrowed it down to two patches it was likely to be - something in rust-lang#128796, probably rust-lang#128221 or rust-lang#128679.
See zulip for some context. Adds implied target features, e.g.
#[target_feature(enable = "avx2")]
acts like#[target_feature(enable = "avx2,avx,sse4.2,sse4.1...")]
. Fixes #128125, fixes #128426The implied feature sets are taken from the rust reference, there are certainly more features and targets to add.
Please feel free to reassign this to whoever should review it.
r? @Amanieu