Skip to content

Commit

Permalink
JIT: fix count reconstruction problem
Browse files Browse the repository at this point in the history
In large methods with lots of irreducible loops we may find
reconstructed counts reaching very large values.

Since profile counts in practice won't ever be much larger than say
10^12, detect when reconstructed counts exceed this value, and stop
the algorithm.

We may eventually decide to rerun in "hard blend" mode where we
intentionally limit the edge likelihood ranges. But this should do for
now.

Closes dotnet#100350.
  • Loading branch information
AndyAyersMS committed Mar 28, 2024
1 parent e04d9aa commit bf5b1c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/coreclr/jit/fgprofilesynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,12 @@ void ProfileSynthesis::GaussSeidelSolver()
residual = change;
residualBlock = block;
}

if (newWeight >= maxCount)
{
JITDUMP("count overflow in " FMT_BB ": " FMT_WT "\n", block->bbNum, newWeight);
m_overflow = true;
}
}

// If there were no improper headers, we will have converged in one pass.
Expand All @@ -1312,6 +1318,12 @@ void ProfileSynthesis::GaussSeidelSolver()
break;
}

if (m_overflow)
{
printf("*** Overflowed counts in %s\n", m_comp->info.compFullName);
break;
}

// If we have been iterating for a bit, estimate the dominant GS
// eigenvalue. (we might want to start with Jacobi iterations
// to get the Jacobi eigenvalue instead).
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/fgprofilesynthesis.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ProfileSynthesis
static constexpr weight_t ilNextLikelihood = 0.52;
static constexpr weight_t loopBackLikelihood = 0.9;
static constexpr weight_t loopExitLikelihood = 0.9;
static constexpr weight_t maxCount = 1e12;

void Run(ProfileSynthesisOption option);

Expand Down Expand Up @@ -84,6 +85,7 @@ class ProfileSynthesis
unsigned m_improperLoopHeaders = 0;
unsigned m_cappedCyclicProbabilities = 0;
bool m_approximate = false;
bool m_overflow = false;
};

#endif // !_FGPROFILESYNTHESIS_H_

0 comments on commit bf5b1c0

Please sign in to comment.