Skip to content

Propagate block coldness across unwind edges and mark cold callsites - #165101

Draft
stephenduong1004 wants to merge 1 commit into
rust-lang:mainfrom
stephenduong1004:propagate-cold
Draft

stephenduong1004 wants to merge 1 commit into
rust-lang:mainfrom
stephenduong1004:propagate-cold

Conversation

@stephenduong1004

Copy link
Copy Markdown
Contributor

During MIR codegen, find_cold_blocks identifies basic blocks that end in Unreachable or call a #[cold] function and propagates coldness backward to predecessor blocks when all of their successors are cold. However, Terminator::successors includes is_cleanup landingpad edges on unwinding Call terminators. Because shared cleanup landingpads are also reachable from hot callsites and are not marked cold, any intermediate block on a panic path that makes an unwinding call (such as core::fmt::Argument::new_display or core::fmt::Arguments::new before panic_fmt) fails to be marked cold. In addition, rustc_codegen_ssa only used cold_blocks to attach unlikely branch weights to SwitchInt terminators and never marked calls inside cold non-cleanup blocks with the LLVM cold callsite attribute.

This PR filters out is_cleanup successors when propagating coldness backward in find_cold_blocks and adds BuilderMethods::apply_attrs_to_cold_callsite in rustc_codegen_ssa and rustc_codegen_llvm and invoke it from TerminatorCodegenHelper::do_call.

@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 Oct 28, 2026
@rustbot

rustbot commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

r? @ShoyuVanilla

rustbot has assigned @ShoyuVanilla.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: codegen, compiler
  • codegen, compiler expanded to 77 candidates
  • Random selection from 21 candidates

@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@ShoyuVanilla

Copy link
Copy Markdown
Member

Sorry, I'm not so confident with cg 😅
@rustbot reroll

@rustbot rustbot assigned mu001999 and unassigned ShoyuVanilla Oct 29, 2026
@mu001999

Copy link
Copy Markdown
Member

@rustbot reroll

@rustbot rustbot assigned dingxiangfei2009 and unassigned mu001999 Oct 29, 2026
@Kobzol

Kobzol commented Oct 29, 2026

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 29, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 29, 2026
Propagate block coldness across unwind edges and mark cold callsites
@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 378b528 (378b52893a5b1c02acd98ec10276892825bd1be0)
Base parent: 96a18bf (96a18bf5ffa2b24f9cf3d1c731a9eb121c1acad9)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown

Finished benchmarking commit (378b528): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=iffy rustc-perf
@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.3% [0.1%, 0.5%] 7
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.2%] 16
All ❌✅ (primary) 0.3% [0.1%, 0.5%] 7

Max RSS (memory usage)

Results (secondary 0.9%)

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.2%, 3.4%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.9% [-2.9%, -2.9%] 1
All ❌✅ (primary) - - 0

Cycles

Results (primary -3.7%)

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)
- - 0
Improvements ✅
(primary)
-3.7% [-3.9%, -3.6%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.7% [-3.9%, -3.6%] 2

Binary size

Results (primary 0.0%, secondary -0.1%)

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

mean range count
Regressions ❌
(primary)
0.0% [0.0%, 0.0%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 2
All ❌✅ (primary) 0.0% [0.0%, 0.0%] 2

Bootstrap: 487.353s -> 486.845s (-0.10%)
Artifact size: 406.68 MiB -> 406.89 MiB (0.05%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 29, 2026
@stephenduong1004
stephenduong1004 marked this pull request as draft November 9, 2026 20:30
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 9, 2026
@rust-bors

rust-bors Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #166674) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

This branch has not been deployed

No deployments
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. perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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