Skip to content

Commit

Permalink
JIT: revise how synthesis treats handler regions (dotnet#100899)
Browse files Browse the repository at this point in the history
Instead of giving hander regions a fraction of the entry weight, give them a small
fixed weight. This is intended to combat the lack of profile propagation out of
handler regions, where there are currently sometimes weight discontinuities large
enough to cause profile check asserts.

Contributes to dotnet#93020.
  • Loading branch information
AndyAyersMS authored and matouskozak committed Apr 30, 2024
1 parent 8235e6a commit f9e8062
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
19 changes: 9 additions & 10 deletions src/coreclr/jit/fgprofilesynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,29 +1039,28 @@ void ProfileSynthesis::AssignInputWeights(ProfileSynthesisOption option)

// Determine input weight for EH regions, if any.
//
weight_t exceptionScaleFactor = exceptionScale;
weight_t ehWeight = exceptionWeight;

#ifdef DEBUG
if (JitConfig.JitSynthesisExceptionScale() != nullptr)
if (JitConfig.JitSynthesisExceptionWeight() != nullptr)
{
ConfigDoubleArray JitSynthesisExceptionScaleArray;
JitSynthesisExceptionScaleArray.EnsureInit(JitConfig.JitSynthesisExceptionScale());
weight_t newFactor = JitSynthesisExceptionScaleArray.GetData()[0];
ConfigDoubleArray JitSynthesisExceptionWeightArray;
JitSynthesisExceptionWeightArray.EnsureInit(JitConfig.JitSynthesisExceptionWeight());
weight_t newFactor = JitSynthesisExceptionWeightArray.GetData()[0];

if ((newFactor >= 0) && (newFactor <= 1.0))
{
exceptionScaleFactor = newFactor;
ehWeight = newFactor;
}
}
#endif

JITDUMP("Synthesis: exception scale factor " FMT_WT "\n", exceptionScaleFactor);
const weight_t ehWeight = entryWeight * exceptionScaleFactor;
JITDUMP("Synthesis: exception weight " FMT_WT "\n", ehWeight);

if (ehWeight != 0)
{
// We can't inline methods with EH, also inlinees share the parent
// EH tab, so we can't rely on this being empty.
// We can't inline methods with EH. Inlinees share the parent
// EH tab, so we can't rely on the EH table being empty.
//
if (!m_comp->compIsForInlining())
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgprofilesynthesis.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ProfileSynthesis
{
}

static constexpr weight_t exceptionScale = 0.001;
static constexpr weight_t exceptionWeight = 0.00001;
static constexpr weight_t initialBlendFactor = 0.05;
static constexpr weight_t blendFactorGrowthRate = 3;
static constexpr weight_t cappedLikelihood = 0.999;
Expand Down
7 changes: 2 additions & 5 deletions src/coreclr/jit/jitconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -719,18 +719,15 @@ CONFIG_INTEGER(JitRandomlyCollect64BitCounts, W("JitRandomlyCollect64BitCounts")
// 3: profile synthesis for root methods, blend with existing PGO data
CONFIG_INTEGER(JitSynthesizeCounts, W("JitSynthesizeCounts"), 0)

// Check if synthesis left consistent counts
CONFIG_INTEGER(JitCheckSynthesizedCounts, W("JitCheckSynthesizedCounts"), 0)

// If instrumenting the method, run synthesis and save the synthesis results
// as edge or block profile data. Do not actually instrument.
CONFIG_INTEGER(JitPropagateSynthesizedCountsToProfileData, W("JitPropagateSynthesizedCountsToProfileData"), 0)

// Use general (gauss-seidel) solver
CONFIG_INTEGER(JitSynthesisUseSolver, W("JitSynthesisUseSolver"), 1)

// Relative likelihood of exceptions for synthesis
CONFIG_STRING(JitSynthesisExceptionScale, W("JitSynthesisExceptionScale"))
// Weight for exception regions for synthesis
CONFIG_STRING(JitSynthesisExceptionWeight, W("JitSynthesisExceptionWeight"))

// Devirtualize virtual calls with getExactClasses (NativeAOT only for now)
RELEASE_CONFIG_INTEGER(JitEnableExactDevirtualization, W("JitEnableExactDevirtualization"), 1)
Expand Down

0 comments on commit f9e8062

Please sign in to comment.