-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Run LLVM coverage instrumentation passes before optimization passes #83666
Conversation
This matches the behavior of Clang and allows us to remove several hacks which were needed to ensure functions weren't optimized away before reaching the instrumentation pass.
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.
Looks great! Thanks!
@@ -28,12 +28,6 @@ pub fn used_inline_function() { | |||
} | |||
use_this_lib_crate(); | |||
} |
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.
Any theories why this is no longer generating the Unexecuted instantiation
? It probably doesn't have to be documented here anymore (the absence of the unexpected should be expected, so this is good), but I'm curious why it changed.
Here's a trick for keeping the diffs clean in the expected
results, above. The line numbers in llvm-cov show
mess things up, so I avoid changing line numbers whenever possible: Just replace these 6 deleted lines with 6 blank lines.
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.
The Unexecuted instantiation
re-appears if I undo the changes in compiler/rustc_typeck/src/collect.rs
. I'm not exactly sure how that causes it to re-appear though.
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.
Yeah, I assumed it's related somehow.
Thanks for inserting the blank lines. Makes the expected result diffs a lot easier to read!
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.
Do you want me to remove the blank lines before merging?
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.
Not necessary. Thanks.
@@ -548,6 +548,11 @@ pub(crate) unsafe fn optimize( | |||
llvm::LLVMRustAddPass(fpm, find_pass("lint").unwrap()); | |||
continue; | |||
} | |||
if pass_name == "insert-gcov-profiling" || pass_name == "instrprof" { | |||
// Instrumentation should be inserted before optimization. |
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.
Can we say "must" instead of "should" and reference the Issue number?
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 couldn't find a suitable issue to point to so I just pointed at the Clang code.
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.
You're updated comment works for me. Thanks!
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.
Sorry, I just realized that the existing tests in the rust compiler don't confirm that your fix for the inline always actually works. See my comment about how to test this. Thanks!
} else { | ||
InlineAttr::Always | ||
} | ||
InlineAttr::Always |
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.
Oh, before you make this change, we need to test that this doesn't break the brotli_decompressor
See #82875
I was not able to create a coverage test that failed in the way it fails in this issue, but by not forcing inline always, the issue was resolved.
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 just tested the example from that issue. It fails on my main rustc (2021-03-24 nightly) but succeeds on my new branch. So the fix for inline always works.
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.
That's great.
Before merging, I'd like to try your patch on some creates I had issues with.
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 cherry-picked your branch commits and am testing them now.
I'm having an issue compiling the brotli_decompressor test with anything higher than I don't remember ever having to wait very long for the compiler to compile and link one small program like this. Is it possible your change could significantly slow down the optimization passes? extern crate brotli_decompressor;
use std::io;
fn main() {
match brotli_decompressor::BrotliDecompress(&mut io::stdin(), &mut io::stdout()) {
Ok(_) => {}
Err(e) => println!("Error {:?}", e),
}
} $ time ~/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc -Zinstrument-coverage -Copt-level=1 brotli_covtest.rs -L ~/rust-brotli-decompressor/target/debug/ -L ~/rust-brotli-decompressor/target/debug/deps --edition=2018
real 0m1.111s
user 0m3.136s
sys 0m0.179s
$ time ~/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc -Zinstrument-coverage -Copt-level=2 brotli_covtest.rs -L ~/rust-brotli-decompressor/target/debug/ -L ~/rust-brotli-decompressor/target/debug/deps --edition=2018
real 0m23.503s
user 0m36.125s
sys 0m0.181s
$ time ~/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc -Zinstrument-coverage -Copt-level=3 brotli_covtest.rs -L ~/rust-brotli-decompressor/target/debug/ -L ~/rust-brotli-decompressor/target/debug/deps --edition=2018
real 0m23.822s
user 0m36.961s
sys 0m0.211s |
I can't reproduce this:
Can you try using |
yes. Also, Let me rebuild the compiler after a clean. I want to make sure I don't have some weird residual code influencing this somehow. |
I'm not seeing an issue after a clean build. Not sure what happened, but I think it was something buggy in my build. Good to go from my perspective. @tmandry - Thumbs up from me. Thanks Amanieu! |
Oh this is great, a big mystery is now solved. Thanks for this! @bors r+ |
📌 Commit cad9b6b has been approved by |
☀️ Test successful - checks-actions |
Big deviations on kessak-debug and unicode_normalization-debug with incr-full, but maybe this is random thing. |
The changes in PR only apply if |
Currently rust-perf site works slow for me, maybe that affects backend performance collection process too? |
Checked next pr, the same thing https://perf.rust-lang.org/compare.html?start=2a32abbcdea97c6bf1d0445bc657f16c50ca103b&end=a5029ac0ab372aec515db2e718da6d7787f3d122&stat=max-rss Maybe some issues with performance collecting, or i checking wrong commits :-( |
This matches the behavior of Clang and allows us to remove several
hacks which were needed to ensure functions weren't optimized away
before reaching the instrumentation pass.
Fixes #83429
cc @richkadel
r? @tmandry