Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6947,7 +6947,7 @@ class Compiler
void fgDebugCheckFlagsHelper(GenTree* tree, GenTreeFlags actualFlags, GenTreeFlags expectedFlags);
void fgDebugCheckTryFinallyExits();
void fgDebugCheckProfile(PhaseChecks checks = PhaseChecks::CHECK_NONE);
bool fgDebugCheckProfileWeights(ProfileChecks checks);
bool fgDebugCheckProfileWeights(ProfileChecks checks, bool dump = false);
bool fgDebugCheckIncomingProfileData(BasicBlock* block, ProfileChecks checks);
bool fgDebugCheckOutgoingProfileData(BasicBlock* block, ProfileChecks checks);

Expand Down
15 changes: 12 additions & 3 deletions src/coreclr/jit/fgprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4595,6 +4595,8 @@ void Compiler::fgDebugCheckProfile(PhaseChecks checks)
//
// Arguments:
// checks - checker options
// dump - if true, report inconsistencies via JITDUMP without asserting (used by the
// re-run below to log details before the initial pass asserts)
//
Comment thread
AndyAyersMS marked this conversation as resolved.
// Returns:
// True if all enabled checks pass
Expand All @@ -4610,7 +4612,7 @@ void Compiler::fgDebugCheckProfile(PhaseChecks checks)
// There's no point checking until we've built pred lists, as
// we can't easily reason about consistency without them.
//
bool Compiler::fgDebugCheckProfileWeights(ProfileChecks checks)
bool Compiler::fgDebugCheckProfileWeights(ProfileChecks checks, bool dump)
{
// We can check classic (min/max, late computed) weights
// and/or
Expand Down Expand Up @@ -4845,13 +4847,20 @@ bool Compiler::fgDebugCheckProfileWeights(ProfileChecks checks)

// Note we only assert when we think the profile data should be consistent.
//
if (assertOnFailure)
if (assertOnFailure && !dump)
{
// Re-run with dumping forced on so the offending blocks are logged before we assert.
//
const bool wasVerbose = verbose;
verbose = true;
fgDebugCheckProfileWeights(checks, /* dump */ true);
verbose = wasVerbose;

assert(!"Inconsistent profile data");
}
}

if (unflaggedBlocks > 0)
if ((unflaggedBlocks > 0) && !dump)
{
JITDUMP("%d blocks are missing BBF_PROF_WEIGHT flag.\n", unflaggedBlocks);
assert(!"Missing BBF_PROF_WEIGHT flag");
Expand Down
10 changes: 6 additions & 4 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,15 +1306,17 @@ GenTree* Lowering::LowerSwitch(GenTree* node)
bool profileInconsistent = false;
for (unsigned i = 0; i < targetCnt; i++)
{
FlowEdge* const edge = uniqueSuccs[i];
weight_t const oldEdgeWeight = edge->getLikelyWeight();
FlowEdge* const edge = uniqueSuccs[i];
edge->setLikelihood(newLikelihood * edge->getDupCount());
weight_t const newEdgeWeight = edge->getLikelyWeight();

if (afterDefaultCondBlock->hasProfileWeight())
{
// Recompute the target's weight from its incoming edges rather than adjusting
// it incrementally: the earlier default-peel scaled afterDefaultCondBlock's
// weight but left the switch targets' weights stale, so an incremental update
// would accumulate on top of a stale value (see #130785).
BasicBlock* const targetBlock = edge->getDestinationBlock();
targetBlock->increaseBBProfileWeight(newEdgeWeight - oldEdgeWeight);
targetBlock->setBBProfileWeight(targetBlock->computeIncomingWeight());
profileInconsistent |= (targetBlock->NumSucc() > 0);
}
}
Expand Down
Loading