Skip to content

Commit

Permalink
JIT: Use fgCalledCount for OSR method entry weight (#112662)
Browse files Browse the repository at this point in the history
Follow-up to #112499. By ensuring OSR method entry blocks' weights match fgCalledCount during entry canonicalization, we can guarantee that later runs of profile synthesis won't modify fgCalledCount. This should unblock #111915 (comment).
  • Loading branch information
amanasifkhalid authored Feb 19, 2025
1 parent 9283581 commit 8b6071e
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4046,18 +4046,13 @@ void Compiler::fgFixEntryFlowForOSR()

fgRedirectTargetEdge(fgFirstBB, fgOSREntryBB);

// We don't know the right weight for this block, since
// execution of the method was interrupted within the
// loop containing fgOSREntryBB.
//
// A plausible guess might be to sum the non-backedge
// weights of fgOSREntryBB and use those, but we don't
// have edge weights available yet. Note that might be
// an underestimate.
//
// For now we just guess that the loop will execute 100x.
//
fgFirstBB->inheritWeightPercentage(fgOSREntryBB, 1);
fgFirstBB->bbWeight = fgCalledCount;
fgFirstBB->CopyFlags(fgEntryBB, BBF_PROF_WEIGHT);

if (fgCalledCount == BB_ZERO_WEIGHT)
{
fgFirstBB->bbSetRunRarely();
}

JITDUMP("OSR: redirecting flow at method entry from " FMT_BB " to OSR entry " FMT_BB " for the importer\n",
fgFirstBB->bbNum, fgOSREntryBB->bbNum);
Expand Down

0 comments on commit 8b6071e

Please sign in to comment.