Skip to content

Commit

Permalink
JIT: prefer edge counts; keep class profiles even if tossing counts (#…
Browse files Browse the repository at this point in the history
…85406)

If there are both edge and block counts for a method, prefer to use the
edge counts (block counts are no longer the default, so are more likely
to be stale).

Sometimes we decide not to use count data because of correlation or
solver issues. When this happens, keep the class profile data viable
and let the code that deals with class profiles handle the possibility
of stale or mismatched data.

Addresses some aspects of #84446, though it's still not clear why we see
static profiles with both block and edge counts.
  • Loading branch information
AndyAyersMS committed Apr 27, 2023
1 parent 86c71e4 commit e029183
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/coreclr/jit/fgprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2707,29 +2707,19 @@ PhaseStatus Compiler::fgIncorporateProfileData()

if (fgPgoHaveWeights)
{
// We expect not to have both block and edge counts. We may have other
// forms of profile data even if we do not have any counts.
// If for some reason we have both block and edge counts, prefer the edge counts.
//
// As of 4/6/2023 the following invariant check turns out to no longer hold.
// Tracking issue: https://github.com/dotnet/runtime/issues/84446
//
// assert(!haveBlockCounts || !haveEdgeCounts);

bool dataIsGood = false;

if (haveBlockCounts)
if (haveEdgeCounts)
{
dataIsGood = fgIncorporateBlockCounts();
dataIsGood = fgIncorporateEdgeCounts();
}
else if (haveEdgeCounts)
else if (haveBlockCounts)
{
dataIsGood = fgIncorporateEdgeCounts();
dataIsGood = fgIncorporateBlockCounts();
}

// Profile incorporation may have tossed out all PGO data if it
// encountered major issues. This is perhaps too drastic. Consider
// at least keeping the class profile data, or perhaps enable full synthesis.
//
// If profile incorporation hit fixable problems, run synthesis in blend mode.
//
if (fgPgoHaveWeights && !dataIsGood)
Expand Down Expand Up @@ -3554,10 +3544,9 @@ void EfficientEdgeCountReconstructor::Propagate()
//
if (m_badcode || m_mismatch || m_failedToConverge || m_allWeightsZero)
{
// Make sure nothing else in the jit looks at the profile data.
// Make sure nothing else in the jit looks at the count profile data.
//
m_comp->fgPgoHaveWeights = false;
m_comp->fgPgoSchema = nullptr;

if (m_badcode)
{
Expand All @@ -3576,7 +3565,7 @@ void EfficientEdgeCountReconstructor::Propagate()
m_comp->fgPgoFailReason = "PGO data available, profile data was all zero";
}

JITDUMP("... discarding profile data: %s\n", m_comp->fgPgoFailReason);
JITDUMP("... discarding profile count data: %s\n", m_comp->fgPgoFailReason);
return;
}

Expand Down

0 comments on commit e029183

Please sign in to comment.