Skip to content

Add Context-Sensitive IR PGO (CSIR PGO) #118562

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

Open
zamazan4ik opened this issue Dec 3, 2023 · 5 comments
Open

Add Context-Sensitive IR PGO (CSIR PGO) #118562

zamazan4ik opened this issue Dec 3, 2023 · 5 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-enhancement Category: An issue proposing an enhancement or a PR with one. C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zamazan4ik
Copy link
Contributor

zamazan4ik commented Dec 3, 2023

Clang has support for an additional PGO mode - Context-Sensitive PGO. This is completely the same way as now used by Rustc but the main difference is when instrumentation is done. In usual (IR PGO) instrumentation is done before the inlining phase, with CSIR PGO - after the inlining phase. This could be important since the inlining decisions can introduce some noise into the profiling information.

In llvm/llvm-project#56274 (comment) comment, there is a small insight into the actual effects on the performance. According to this, we can treat CSIR PGO as a light replacement for LLVM BOLT optimization. For some people, it could be important since LLVM BOLT does not work on all platforms.

Right now it's not clear, could we implement CSIR PGO by just passing the right LLVM flag, or some frontend changes are required too? I guess some CSIR PGO implementation in Clang is required here. In any way, CSIR PGO information should be added to the Rustc PGO documentation.

CSIR PGO also was mentioned in the initial PGO issue for Rustc: #59913 (comment)

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 3, 2023
@zamazan4ik
Copy link
Contributor Author

Helpful insights can be found here: https://reviews.llvm.org/D54176

@Kobzol
Copy link
Contributor

Kobzol commented Dec 6, 2023

I have already tried CSIR PGO several times for rustc's LLVM (#97153, #111806), but couldn't get any performance benefits out of it. When I discussed it with BOLT maintainers on Discord, they basically told me that CSIR's optimizations are subsumed by BOLT. And since we already use BOLT both for rustc and LLVM, I don't think that CSIR will help much.

@zamazan4ik
Copy link
Contributor Author

zamazan4ik commented Dec 6, 2023

I have seen this discussion. However, I disagree that CSIR PGO has no sense because we have LLVM BOLT. BOLT has many limitations (lack of support for multiple platforms important platforms like Windows, macOS and *BSD, resource consumption during the optimization phase, multiple bugs). Since all of these, there are a lot of applications that simply cannot use BOLT in their optimization pipelines.

Even if for the Rustc itself could be less sense to use CSIR PGO in its optimization pipelines (however CSIR PGO should be useful for Windows and macOS builds at least), CSIR PGO support could be useful for other Rust applications.

Regarding the actual benchmark improvements from PGO - I already requested some numbers from Google people. Hopefully, they will be able to share them. If I get enough time, probably I can perform my own benchmarks too.

@Kobzol
Copy link
Contributor

Kobzol commented Dec 6, 2023

Yeah I don't dispute that, I just wanted to mention that for x64 Linux rustc/LLVM it's probably not worth investing effort into. It could be useful for general Rust programs or rustc on other platforms (but there it's quite problematic, since CI time is typically quite limited and we don't even have benchmarking for non-Linux systems currently).

@Jules-Bertholet
Copy link
Contributor

@rustbot label T-compiler C-optimization C-enhancement A-LLVM

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-enhancement Category: An issue proposing an enhancement or a PR with one. C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 15, 2023
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-enhancement Category: An issue proposing an enhancement or a PR with one. C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants