diff --git a/src/coreclr/jit/fgprofile.cpp b/src/coreclr/jit/fgprofile.cpp index a215559cbdb2f..bf62914c5444c 100644 --- a/src/coreclr/jit/fgprofile.cpp +++ b/src/coreclr/jit/fgprofile.cpp @@ -2697,12 +2697,12 @@ PhaseStatus Compiler::fgIncorporateProfileData() // 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 repair mode. + // If profile incorporation hit fixable problems, run synthesis in blend mode. // if (fgPgoHaveWeights && !dataIsGood) { - JITDUMP("\nIncorporated count data had inconsistencies; repairing profile...\n"); - ProfileSynthesis::Run(this, ProfileSynthesisOption::RepairLikelihoods); + JITDUMP("\nIncorporated count data had inconsistencies; blending profile...\n"); + ProfileSynthesis::Run(this, ProfileSynthesisOption::BlendLikelihoods); } } diff --git a/src/coreclr/jit/fgprofilesynthesis.cpp b/src/coreclr/jit/fgprofilesynthesis.cpp index 4930122f50ae0..286510cf71d60 100644 --- a/src/coreclr/jit/fgprofilesynthesis.cpp +++ b/src/coreclr/jit/fgprofilesynthesis.cpp @@ -620,9 +620,12 @@ void ProfileSynthesis::BlendLikelihoods() case BBJ_COND: case BBJ_SWITCH: { - // Capture the existing weights and assign new - // weights based on heuristics. - weight_t sum = SumOutgoingLikelihoods(block, &likelihoods); + // Capture the existing weights and assign new likelihoods based on synthesis. + // + weight_t const sum = SumOutgoingLikelihoods(block, &likelihoods); + bool const unlikely = Compiler::fgProfileWeightsEqual(sum, 0.0, epsilon); + bool const consistent = Compiler::fgProfileWeightsEqual(sum, 1.0, epsilon); + bool const zero = Compiler::fgProfileWeightsEqual(block->bbWeight, 0.0, epsilon); if (block->bbJumpKind == BBJ_COND) { @@ -633,10 +636,12 @@ void ProfileSynthesis::BlendLikelihoods() AssignLikelihoodSwitch(block); } - if (Compiler::fgProfileWeightsEqual(sum, 0.0, epsilon)) + if (unlikely || zero) { - // Existing likelihood was zero. Go with the synthesized likelihoods. - JITDUMP("Existing likelihoods in " FMT_BB " were zero, synthesizing new ones\n", block->bbNum); + // Existing likelihood was zero, or profile weight was zero. Just use synthesis likelihoods. + // + JITDUMP("%s in " FMT_BB " was zero, using synthesized likelihoods\n", + unlikely ? "Existing likelihood" : "Block weight", block->bbNum); break; } @@ -645,6 +650,7 @@ void ProfileSynthesis::BlendLikelihoods() if (!Compiler::fgProfileWeightsEqual(sum, 1.0, epsilon)) { // Existing likelihood was too low or too high. Scale. + // weight_t scale = 1.0 / sum; JITDUMP("Scaling old likelihoods in " FMT_BB " by " FMT_WT "\n", block->bbNum, scale); for (iter = likelihoods.begin(); iter != likelihoods.end(); iter++)