From 712bc60a84ad056dff741ef3397a6f8ebbbbb369 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Sun, 14 Feb 2021 09:40:34 -0800 Subject: [PATCH] JIT: allow inlinee profile scale-up We can't always be sure that callee entry counts will be greater than or equal to call site counts. For example a callee could be tiered up before a caller, and so have relatively smaller counts. So, when computing inline scale, allow callee counts to be scaled up as well as scaled down. --- src/coreclr/jit/fgprofile.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/coreclr/jit/fgprofile.cpp b/src/coreclr/jit/fgprofile.cpp index eb40aa80808fbb..d2c567fbfc40e6 100644 --- a/src/coreclr/jit/fgprofile.cpp +++ b/src/coreclr/jit/fgprofile.cpp @@ -118,22 +118,27 @@ void Compiler::fgComputeProfileScale() return; } - // Note when/if we do normalization this may need to change. + // Note when/if we early do normalization this may need to change. // - BasicBlock::weight_t calleeWeight = fgFirstBB->bbWeight; + BasicBlock::weight_t const calleeWeight = fgFirstBB->bbWeight; - // We should generally be able to assume calleeWeight >= callSiteWeight. - // If this isn't so, perhaps something is wrong with the profile data - // collection or retrieval. + // If profile data reflects a complete single run we can expect + // calleeWeight >= callSiteWeight. // - if (calleeWeight < callSiteWeight) + // However if our profile is just a subset of execution we may + // not see this. + // + // So, we are willing to scale the callee counts down or up as + // needed to match the call site. + // + if (calleeWeight == BB_ZERO_WEIGHT) { - JITDUMP(" ... callee entry count %f is less than call site count %f\n", calleeWeight, callSiteWeight); + JITDUMP(" ... callee entry count is zero\n"); impInlineInfo->profileScaleState = InlineInfo::ProfileScaleState::UNAVAILABLE; return; } - // Hence, scale is always in the range (0.0...1.0] -- we are always scaling down callee counts. + // Hence, scale can be somewhat arbitrary... // const double scale = ((double)callSiteWeight) / calleeWeight; impInlineInfo->profileScaleFactor = scale;