Skip to content

Various refactors to the LTO handling code (part 2) #144062

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

Merged
merged 6 commits into from
Jul 24, 2025

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jul 17, 2025

Continuing from #143388 this removes a bit of dead code and moves the LTO symbol export calculation from individual backends to cg_ssa.

@rustbot
Copy link
Collaborator

rustbot commented Jul 17, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 17, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the lto_refactors2 branch 2 times, most recently from 0044549 to 7026d08 Compare July 17, 2025 10:04
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the lto_refactors2 branch 2 times, most recently from bab46eb to 217e5de Compare July 17, 2025 11:27
@rust-log-analyzer

This comment has been minimized.

@lcnr
Copy link
Contributor

lcnr commented Jul 17, 2025

looked through all the commits and while they look good to me, I don't feel comfortable actually judging these changes, so

r? compiler

@rustbot rustbot assigned davidtwco and unassigned lcnr Jul 17, 2025
@@ -355,23 +356,28 @@ impl WriteBackendMethods for GccCodegenBackend {

fn run_and_optimize_fat_lto(
cgcx: &CodegenContext<Self>,
// FIXME(bjorn3): Limit LTO exports to these symbols
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean exactly?
Does that mean that only those symbols should be exported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is a superset of the set of symbols that will be exported by the linker (it also includes #[used] symbols to ensure those are kept by LTO). By already marking the rest as non-exported during LTO, LTO can optimize non-exported functions more aggressively. For example by changing their ABI or dropping them entirely if unused.

@bjorn3 bjorn3 force-pushed the lto_refactors2 branch 2 times, most recently from 6f83685 to 02d63c0 Compare July 17, 2025 16:45
@bjorn3
Copy link
Member Author

bjorn3 commented Jul 17, 2025

Since lcnr's review I've moved the checks for if LTO is allowed to happen right before LTO is done rather than when the coordinator thread starts. This way it doesn't happen for --emit metadata or for non-linked crate types.

Also give than this makes the symbol filtering always happen:

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Jul 17, 2025

⌛ Trying commit 02d63c0 with merge f1a7db9

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jul 17, 2025
Various refactors to the LTO handling code (part 2)

Continuing from #143388 this removes a bit of dead code and moves the LTO symbol export calculation from individual backends to cg_ssa.
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 17, 2025
@rust-bors
Copy link

rust-bors bot commented Jul 17, 2025

☀️ Try build successful (CI)
Build commit: f1a7db9 (f1a7db981fde509fe79c4358b40b84e4ca8d66ce, parent: bf5e6cc7a7a7eb03e3ed9b875d76530eddd47d5f)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f1a7db9): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

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

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.3%, 0.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.4% [-6.8%, -1.2%] 6
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -5.0%, secondary 1.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.8% [2.6%, 3.1%] 2
Improvements ✅
(primary)
-5.0% [-6.8%, -3.7%] 3
Improvements ✅
(secondary)
-2.5% [-2.5%, -2.5%] 1
All ❌✅ (primary) -5.0% [-6.8%, -3.7%] 3

Cycles

Results (secondary -1.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.4% [2.1%, 2.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.7% [-5.9%, -3.3%] 3
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 464.659s -> 464.118s (-0.12%)
Artifact size: 374.78 MiB -> 374.77 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 17, 2025
bjorn3 added 6 commits July 21, 2025 07:58
The modules vec can already contain serialized modules and there is no
need to distinguish between cached and non-cached cgus at LTO time.
It isn't used anywhere. Also inline free_worker into the only call site.
And move exported_symbols_for_lto call from backends to cg_ssa.
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davidtwco
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 24, 2025

📌 Commit dadc4ca has been approved by davidtwco

It is now in the queue for this repository.

@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 Jul 24, 2025
@bors
Copy link
Collaborator

bors commented Jul 24, 2025

⌛ Testing commit dadc4ca with merge 5d22242...

@bors
Copy link
Collaborator

bors commented Jul 24, 2025

☀️ Test successful - checks-actions
Approved by: davidtwco
Pushing 5d22242 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 24, 2025
@bors bors merged commit 5d22242 into rust-lang:master Jul 24, 2025
12 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 24, 2025
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing fc5af18 (parent) -> 5d22242 (this PR)

Test differences

Show 6 test diffs

Stage 1

  • errors::verify_codegen_ssa_dynamic_linking_with_lto_137: [missing] -> pass (J0)
  • errors::verify_codegen_ssa_lto_disallowed_134: [missing] -> pass (J0)
  • errors::verify_codegen_ssa_lto_dylib_135: [missing] -> pass (J0)
  • errors::verify_codegen_ssa_lto_proc_macro_136: [missing] -> pass (J0)

Additionally, 2 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 5d22242a3a84a55be2f648a94eecff58887547f4 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-apple-1: 8404.4s -> 15027.8s (78.8%)
  2. dist-x86_64-apple: 9040.1s -> 10506.4s (16.2%)
  3. tidy: 123.6s -> 104.6s (-15.3%)
  4. dist-aarch64-apple: 7014.0s -> 7959.2s (13.5%)
  5. x86_64-apple-2: 5138.4s -> 4666.8s (-9.2%)
  6. dist-ohos-armv7: 4247.7s -> 3873.8s (-8.8%)
  7. dist-various-1: 4292.5s -> 3935.1s (-8.3%)
  8. dist-x86_64-linux-alt: 7347.4s -> 7899.2s (7.5%)
  9. aarch64-apple: 5304.7s -> 5694.7s (7.4%)
  10. aarch64-gnu-llvm-19-1: 3452.8s -> 3210.4s (-7.0%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5d22242): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.4% [-6.7%, -1.1%] 6
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -3.4%, secondary -1.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.7% [2.7%, 2.7%] 1
Improvements ✅
(primary)
-3.4% [-5.5%, -1.1%] 6
Improvements ✅
(secondary)
-1.7% [-4.9%, -1.0%] 6
All ❌✅ (primary) -3.4% [-5.5%, -1.1%] 6

Cycles

Results (primary 2.0%, secondary -2.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.0% [2.0%, 2.1%] 3
Regressions ❌
(secondary)
3.3% [3.3%, 3.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.1% [-5.7%, -2.5%] 4
All ❌✅ (primary) 2.0% [2.0%, 2.1%] 3

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 468.258s -> 466.913s (-0.29%)
Artifact size: 374.68 MiB -> 374.67 MiB (-0.00%)

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. 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