Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

JIT: fix profile propagation in LowerSwitch - #130907

#130907
Merged
AndyAyersMS merged 1 commit into
dotnet:maindotnet/runtime:mainfrom
AndyAyersMS:fix-130785-cond-collapse-likelihoodAndyAyersMS/runtime:fix-130785-cond-collapse-likelihoodCopy head branch name to clipboard
Jul 21, 2026
Merged

JIT: fix profile propagation in LowerSwitch#130907
AndyAyersMS merged 1 commit into
dotnet:maindotnet/runtime:mainfrom
AndyAyersMS:fix-130785-cond-collapse-likelihoodAndyAyersMS/runtime:fix-130785-cond-collapse-likelihoodCopy head branch name to clipboard

Conversation

@AndyAyersMS

@AndyAyersMS AndyAyersMS commented Jul 16, 2026

Copy link
Copy Markdown
Member

Recompute switch target block weights rather than trying to fix them incrementally.

Fixes #130785

Copilot AI review requested due to automatic review settings July 16, 2026 18:57
@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 Jul 16, 2026
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@EgorBo PTAL
fyi @dotnet/jit-contrib

@AndyAyersMS
AndyAyersMS requested a review from EgorBo July 16, 2026 18:58
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 CoreCLR JIT profile-consistency handling in two places: (1) it adds a “dump-only” mode to the debug profile-weight checker so it can log details before asserting, and (2) it ensures edge-likelihood invariants are maintained when conditional branches are collapsed to unconditional branches.

Changes:

  • Extend fgDebugCheckProfileWeights with a dump mode and re-run the check with verbose=true to emit diagnostics prior to asserting on inconsistent profile data.
  • Normalize the successor edge likelihood when converting a degenerate BBJ_COND to BBJ_ALWAYS.
  • Update the Compiler declaration to match the new fgDebugCheckProfileWeights signature.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/fgprofile.cpp Adds dump mode and a verbose re-run to print profile inconsistency details before asserting.
src/coreclr/jit/fgopt.cpp Adjusts edge likelihood handling when removing a conditional jump that always targets the same block.
src/coreclr/jit/compiler.h Updates the fgDebugCheckProfileWeights declaration to include the new optional dump parameter.
Comments suppressed due to low confidence (1)

src/coreclr/jit/fgprofile.cpp:4867

  • In dump mode, the unflaggedBlocks path is completely suppressed (no JITDUMP, no assert). This defeats the purpose of re-running with dump=true to log details before asserting, since missing BBF_PROF_WEIGHT flags will still assert without any diagnostic output when verbose was originally false. Consider always emitting the JITDUMP, and only gating the assert on !dump.
    if ((unflaggedBlocks > 0) && !dump)
    {
        JITDUMP("%d blocks are missing BBF_PROF_WEIGHT flag.\n", unflaggedBlocks);
        assert(!"Missing BBF_PROF_WEIGHT flag");
    }

Comment thread src/coreclr/jit/fgopt.cpp Outdated

@JulieLeeMSFT JulieLeeMSFT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

When peeling a fully-biased default case, recompute each remaining switch target's
weight from its incoming edges instead of adjusting it incrementally, so return
targets (no successors) don't keep a stale weight and trip the profile check.
Also add an assert-time diagnostic that dumps the offending block.

Fixes dotnet#130785

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9f8414be-99cb-492d-a7c0-091c8e7de191
Copilot AI review requested due to automatic review settings July 18, 2026 02:13
@AndyAyersMS
AndyAyersMS force-pushed the fix-130785-cond-collapse-likelihood branch from c8b1987 to b78cb45 Compare July 18, 2026 02:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/jit/fgprofile.cpp
@AndyAyersMS AndyAyersMS changed the title JIT: normalize edge likelihood when collapsing BBJ_COND to BBJ_ALWAYS JIT: fix profile propagation in LowerSwitch Jul 18, 2026
@AndyAyersMS
AndyAyersMS requested a review from EgorBo July 18, 2026 14:07
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@EgorBo can you re-review. Got a repro finally.

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Workflow state for the Holistic Review Orchestrator.

{
  "version": 5,
  "last_dispatched_commit": "b78cb450324ea0383476421f9d2765e81c671a4b",
  "last_dispatched_base_ref": "main",
  "last_dispatched_base_sha": "e7c3d6567c4d78e0c10627fa89939767464478c2",
  "last_reviewed_commit": "b78cb450324ea0383476421f9d2765e81c671a4b",
  "last_reviewed_base_ref": "main",
  "last_reviewed_base_sha": "e7c3d6567c4d78e0c10627fa89939767464478c2",
  "last_recorded_worker_run_id": "29688126480",
  "review_attempt_commit": "",
  "review_attempt_base_ref": "",
  "review_attempt_count": 0,
  "max_review_attempts": 5,
  "review_history_format": "holistic-review-disclosure-v1",
  "review_history": [
    {
      "commit": "b78cb450324ea0383476421f9d2765e81c671a4b",
      "review_id": 4730808760
    }
  ]
}

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Holistic Review

Motivation: Fixes #130785, an Inconsistent profile data assertion in Lowering. When LowerSwitch peels the default case and then distributes case likelihoods equally (the zero-remaining-likelihood path), it was updating each switch target's block weight incrementally via increaseBBProfileWeight(newEdgeWeight - oldEdgeWeight). Because the earlier default-peel had already scaled afterDefaultCondBlock's weight but left the target weights stale, the incremental delta accumulated on top of a stale base, producing inconsistent profile weights and tripping the debug checker.

Approach: In the equal-distribution loop, the target's weight is now recomputed from scratch from its incoming edges: targetBlock->setBBProfileWeight(targetBlock->computeIncomingWeight()), replacing the fragile incremental adjustment. This mirrors the established pattern already used across the JIT after edge-likelihood changes (optimizebools.cpp, optimizer.cpp, helperexpansion.cpp). The now-unused oldEdgeWeight/newEdgeWeight locals are removed. Separately, fgDebugCheckProfileWeights gains a dump parameter (debug-only): before asserting on inconsistency, it re-runs itself with dumping forced on so the offending blocks are logged in the JIT dump prior to the assert; the missing-flag assert and the recursion are correctly guarded by !dump to avoid double-assert/infinite recursion.

Summary: This is a small, well-targeted correctness fix in profile-weight propagation plus a helpful debug diagnostic. The recompute-from-incoming-edges approach is consistent with existing JIT conventions and is robust against stale base weights. The dump re-run recursion terminates (guarded by !dump) and restores verbose. Note the sibling scaleFactor branch (the non-zero remaining-likelihood path) only adjusts edge likelihoods and does not touch block weights, so it is unaffected by this class of bug. I found no correctness, performance, or convention issues in the changed lines. Behavior in release builds is limited to the one-line weight recomputation; the rest is DEBUG-only. LGTM.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 60.6 AIC · ⌖ 10.5 AIC · ⊞ 10K

@AndyAyersMS
AndyAyersMS merged commit 4d9d5a1 into dotnet:main Jul 21, 2026
141 of 143 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 24, 2026
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.

JIT: Assertion failed '!"Inconsistent profile data"' in 'Lowering nodeinfo'

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.