Skip to content
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

Always include global target features in function attributes #94579

Merged
merged 4 commits into from
Mar 6, 2022

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented Mar 3, 2022

This ensures that information about target features configured with
-C target-feature=... or detected with -C target-cpu=native is
retained for subsequent consumers of LLVM bitcode.

This is crucial for linker plugin LTO, since this information is not
conveyed to the plugin otherwise.

Additional test case demonstrating the issue
extern crate core;

#[inline]
#[target_feature(enable = "aes")]
unsafe fn f(a: u128, b: u128) -> u128 {
    use core::arch::x86_64::*;
    use core::mem::transmute;
    transmute(_mm_aesenc_si128(transmute(a), transmute(b)))
}

pub fn g(a: u128, b: u128) -> u128 {
    unsafe { f(a, b) }
}

fn main() {
    let mut args = std::env::args();
    let _ = args.next().unwrap();
    let a: u128 = args.next().unwrap().parse().unwrap();
    let b: u128 = args.next().unwrap().parse().unwrap();
    println!("{}", g(a, b));
}
$ rustc --edition=2021 a.rs -Clinker-plugin-lto -Clink-arg=-fuse-ld=lld  -Ctarget-feature=+aes -O 
...
  = note: LLVM ERROR: Cannot select: intrinsic %llvm.x86.aesni.aesenc

r? @nagisa

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 3, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 3, 2022
@tmiasko
Copy link
Contributor Author

tmiasko commented Mar 3, 2022

@bors try

@bors
Copy link
Contributor

bors commented Mar 3, 2022

⌛ Trying commit 10fdd56b21c3dbf17c6eae5ad1abbce65137ad62 with merge cdc3d6a5be595fadb021df096cfc2149de5b686e...

@nagisa
Copy link
Member

nagisa commented Mar 3, 2022

Please verify if cross-lang LTO can inline (regular, non-aes) functions between those built with rustc -Ctarget-cpu=native and clang -march=native. I haven't checked if this still works today, but this might fix or break that as well and it'd be good to know either way.

Also, fixes #94326, right?

@bors
Copy link
Contributor

bors commented Mar 3, 2022

☀️ Try build successful - checks-actions
Build commit: cdc3d6a5be595fadb021df096cfc2149de5b686e (cdc3d6a5be595fadb021df096cfc2149de5b686e)

@tmiasko
Copy link
Contributor Author

tmiasko commented Mar 4, 2022

I was testing cross-lang LTO with clang 14 from Debian sid and inlining works fine with rustc -Ctarget-cpu=native and clang -march=native.

The issue addressed here seems is most likely responsible for #94326, but I leave this for the original reporter to verify.

@nagisa
Copy link
Member

nagisa commented Mar 4, 2022

@rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 4, 2022
tmiasko added 4 commits March 4, 2022 16:57
This ensures that information about target features configured with
`-C target-feature=...` or detected with `-C target-cpu=native` is
retained for subsequent consumers of LLVM bitcode.

This is crucial for linker plugin LTO, since this information is not
conveyed to the plugin otherwise.
@nagisa
Copy link
Member

nagisa commented Mar 5, 2022

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@bors
Copy link
Contributor

bors commented Mar 5, 2022

⌛ Trying commit 095d818 with merge 8b23507938335698d132fbfeec3581994b468c68...

@bors
Copy link
Contributor

bors commented Mar 5, 2022

☀️ Try build successful - checks-actions
Build commit: 8b23507938335698d132fbfeec3581994b468c68 (8b23507938335698d132fbfeec3581994b468c68)

@rust-timer
Copy link
Collaborator

Queued 8b23507938335698d132fbfeec3581994b468c68 with parent c8a49fc, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8b23507938335698d132fbfeec3581994b468c68): comparison url.

Summary: This benchmark run did not return any relevant results.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 5, 2022
@nagisa
Copy link
Member

nagisa commented Mar 5, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Mar 5, 2022

📌 Commit 095d818 has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 5, 2022
@bors
Copy link
Contributor

bors commented Mar 6, 2022

⌛ Testing commit 095d818 with merge 81817055727d6d6efc7837463c422ef2b55ea76d...

@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented Mar 6, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 6, 2022
@tmiasko
Copy link
Contributor Author

tmiasko commented Mar 6, 2022

dist-x86_64-apple-alt: The hosted runner: GitHub Actions 28 lost communication with the server.

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 6, 2022
@bors
Copy link
Contributor

bors commented Mar 6, 2022

⌛ Testing commit 095d818 with merge c38b8a8...

@bors
Copy link
Contributor

bors commented Mar 6, 2022

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing c38b8a8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 6, 2022
@bors bors merged commit c38b8a8 into rust-lang:master Mar 6, 2022
@rustbot rustbot added this to the 1.61.0 milestone Mar 6, 2022
@tmiasko tmiasko deleted the target-features branch March 6, 2022 20:35
@bors bors mentioned this pull request Mar 6, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c38b8a8): comparison url.

Summary: This benchmark run did not return any relevant results.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@workingjubilee workingjubilee added the A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. label Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants