Skip to content

JIT: Exclude BB_UNITY_WEIGHT scaling from BasicBlock::isBBWeightCold #116548

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 2 commits into from
Jun 13, 2025

Conversation

amanasifkhalid
Copy link
Member

Motivating example. BB_COLD_WEIGHT is currently 0.01, suggesting blocks that execute less than 1% of the time on average should be considered cold by block layout. However, BasicBlock::isBBWeightCold compares the block's normalized weight (with BB_UNITY_WEIGHT scaling) against BB_COLD_WEIGHT, so the actual cutoff for cold blocks is currently 0.01%. This change removes the BB_UNITY_WEIGHT scaling to get the intended behavior.

@Copilot Copilot AI review requested due to automatic review settings June 11, 2025 17:38
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 11, 2025
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adjusts BasicBlock::isBBWeightCold to compare the raw block weight against the product of call count and the cold-weight threshold, removing the previous unity-weight normalization.

  • Swaps getBBWeight(comp) for bbWeight < (getCalledCount(comp) * BB_COLD_WEIGHT)
  • Aims to restore the intended 1% cutoff for cold blocks rather than 0.01%
Comments suppressed due to low confidence (2)

src/coreclr/jit/block.h:1309

  • There are no tests covering the updated isBBWeightCold behavior; consider adding unit tests for blocks exactly at, just below, and just above the computed cold threshold.
return bbWeight < (getCalledCount(comp) * BB_COLD_WEIGHT);

src/coreclr/jit/block.h:1309

  • The new logic may misclassify blocks when getCalledCount(comp) returns zero, causing all blocks to appear hot. Consider guarding against a zero call count or falling back to a default behavior for unknown call counts.
return bbWeight < (getCalledCount(comp) * BB_COLD_WEIGHT);

@amanasifkhalid
Copy link
Member Author

cc @dotnet/jit-contrib, @AndyAyersMS PTAL. Diffs have quite a bit of churn in both directions, though I'm taking solace in the relatively small PerfScore diffs, since this primarily affects the placement of cold code. I expect this to be a notable regression only in cases where we mistakenly give hot blocks near-zero weight, and we were likely already doing a subpar job with such cases (example). Thanks!

@amanasifkhalid
Copy link
Member Author

ping @AndyAyersMS

@amanasifkhalid
Copy link
Member Author

/ba-g unrelated wasm build failure

@amanasifkhalid amanasifkhalid merged commit d3e2f5e into dotnet:main Jun 13, 2025
107 of 109 checks passed
@amanasifkhalid amanasifkhalid deleted the cold-weight-cutoff branch June 13, 2025 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants