Skip to content

JIT: Fix profile inconsistency asserts in flow graph optimization#127357

Open
AndyAyersMS wants to merge 4 commits intodotnet:mainfrom
AndyAyersMS:fix-profile-inconsistency
Open

JIT: Fix profile inconsistency asserts in flow graph optimization#127357
AndyAyersMS wants to merge 4 commits intodotnet:mainfrom
AndyAyersMS:fix-profile-inconsistency

Conversation

@AndyAyersMS
Copy link
Copy Markdown
Member

Fix three sources of profile weight inconsistency in fgopt.cpp that cause assert failures under PGO stress modes (JitRandomEdgeCounts, JitRandomGuardedDevirtualization):

  1. fgCompactBlock: When compacting a block with a target that had other predecessors removed by earlier transforms, the inherited weight may not match incoming edge weights. Detect this and mark fgPgoConsistent false.

  2. fgOptimizeBranchToEmptyUnconditional: When fgRedirectEdge merges two edges of a BBJ_COND (TrueEdge == FalseEdge), the merged edge retains the old likelihood instead of 1.0. Fix by setting likelihood to 1.0 after merge.

  3. fgOptimizeBranchToEmptyUnconditional: When decreaseBBProfileWeight would clamp a block's weight to zero, mark fgPgoConsistent false.

Also fix three pre-existing misleading JITDUMP messages that said 'Data %s consistent' when marking data as inconsistent.

Fixes #126381.

Fix three sources of profile weight inconsistency in fgopt.cpp that
cause assert failures under PGO stress modes (JitRandomEdgeCounts,
JitRandomGuardedDevirtualization):

1. fgCompactBlock: When compacting a block with a target that had other
   predecessors removed by earlier transforms, the inherited weight may
   not match incoming edge weights. Detect this and mark fgPgoConsistent
   false.

2. fgOptimizeBranchToEmptyUnconditional: When fgRedirectEdge merges two
   edges of a BBJ_COND (TrueEdge == FalseEdge), the merged edge retains
   the old likelihood instead of 1.0. Fix by setting likelihood to 1.0
   after merge.

3. fgOptimizeBranchToEmptyUnconditional: When decreaseBBProfileWeight
   would clamp a block's weight to zero, mark fgPgoConsistent false.

Also fix three pre-existing misleading JITDUMP messages that said
'Data %s consistent' when marking data as inconsistent.

Fixes dotnet#126381.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 23, 2026 22:39
@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 Apr 23, 2026
@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.

Copy link
Copy Markdown
Contributor

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 addresses assert failures under PGO stress modes by tightening/repairing profile consistency tracking in fgopt.cpp during flow-graph optimizations, and fixes a few misleading JITDUMP messages that reported “consistent” while marking the profile as inconsistent.

Changes:

  • In fgCompactBlock, detects post-compaction mismatches between block weight and summed incoming edge flow and marks fgPgoConsistent = false.
  • In fgOptimizeBranchToEmptyUnconditional, fixes the likelihood on a merged conditional edge (true/false now target the same block) by setting it to 1.0.
  • Marks profile inconsistent when decreaseBBProfileWeight would clamp a block’s weight, and corrects several “Data %s consistent” JITDUMP strings to say “inconsistent”.

Comment thread src/coreclr/jit/fgopt.cpp Outdated
AndyAyersMS and others added 2 commits April 23, 2026 15:56
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use block->hasProfileWeight() (post-inheritWeight) instead of the
cached pre-inheritance value, so the check also fires when an
unprofiled block inherits profile weight from a profiled target.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 23, 2026 23:06
Copy link
Copy Markdown
Contributor

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 addresses several sources of PGO/profile-weight inconsistency in CoreCLR JIT flow-graph optimizations (fgopt.cpp) that can trigger asserts under PGO stress modes, and corrects misleading debug dump text when the JIT marks profile data as inconsistent.

Changes:

  • In fgCompactBlock, detect cases where compaction can introduce profile-weight mismatches and mark fgPgoConsistent = false.
  • In fgOptimizeBranchToEmptyUnconditional, correct likelihood after fgRedirectEdge merges conditional edges (ensuring the merged edge has likelihood 1.0), and mark fgPgoConsistent = false when profile weight clamping would occur.
  • Fix JITDUMP messages that previously said “Data %s consistent” while transitioning profile data to an inconsistent state.

Comment thread src/coreclr/jit/fgopt.cpp Outdated
hasLikelihood() is #ifdef DEBUG only and would break Release builds.
Remove the guard and sum getLikelyWeight() unconditionally, since all
edges have likelihoods set by this point in compilation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AndyAyersMS
Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr libraries-pgo

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@AndyAyersMS
Copy link
Copy Markdown
Member Author

@dotnet/jit-contrib PTAL

A very small set of diffs

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

3 participants