Skip to content

Commit

Permalink
JIT: revise inlinee scale computations (#51593)
Browse files Browse the repository at this point in the history
Rework the inlinee profile scale computations so that all scaling happens
during the profile incorporation phase, rather than sometimes deferring
the scaling until inlining. Because of this we no longer need to record
the scale on the inline info.

Toss out profile data if all counts are zero.

Update the edge profile solver to handle a special case where no return block
was executed, but edges within the method had counts. In such cases the entry
block count can end up zero and blocking proper scaling computations. For this
case, try and deduce a plausible count in this case from nearby blocks and edges.

Fix the edge weight computations to tolerate inconsistent data rather than
to assert.
  • Loading branch information
AndyAyersMS committed Apr 21, 2021
1 parent adb3f83 commit a4b0a03
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 171 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5706,7 +5706,7 @@ class Compiler

void WalkSpanningTree(SpanningTreeVisitor* visitor);
void fgSetProfileWeight(BasicBlock* block, BasicBlock::weight_t weight);
void fgComputeProfileScale();
void fgApplyProfileScale();

// fgIsUsingProfileWeights - returns true if we have real profile data for this method
// or if we have some fake profile data for the stress mode
Expand Down
40 changes: 3 additions & 37 deletions src/coreclr/jit/fginline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,6 @@ void Compiler::fgInvokeInlineeCompiler(GenTreeCall* call, InlineResult* inlineRe
inlineInfo.retExprClassHnd = nullptr;
inlineInfo.retExprClassHndIsExact = false;
inlineInfo.inlineResult = inlineResult;
inlineInfo.profileScaleState = InlineInfo::ProfileScaleState::UNDETERMINED;
inlineInfo.profileScaleFactor = 0.0;
#ifdef FEATURE_SIMD
inlineInfo.hasSIMDTypeArgLocalOrReturn = false;
#endif // FEATURE_SIMD
Expand Down Expand Up @@ -1274,10 +1272,6 @@ void Compiler::fgInsertInlineeBlocks(InlineInfo* pInlineInfo)
//
// Set the try and handler index and fix the jump types of inlinee's blocks.
//

bool inheritWeight;
inheritWeight = true; // The firstBB does inherit the weight from the iciBlock

for (block = InlineeCompiler->fgFirstBB; block != nullptr; block = block->bbNext)
{
noway_assert(!block->hasTryIndex());
Expand All @@ -1299,48 +1293,20 @@ void Compiler::fgInsertInlineeBlocks(InlineInfo* pInlineInfo)

if (block->bbJumpKind == BBJ_RETURN)
{
inheritWeight = true; // A return block does inherit the weight from the iciBlock
noway_assert((block->bbFlags & BBF_HAS_JMP) == 0);
if (block->bbNext)
{
JITDUMP("\nConvert bbJumpKind of " FMT_BB " to BBJ_ALWAYS to bottomBlock " FMT_BB "\n", block->bbNum,
bottomBlock->bbNum);
block->bbJumpKind = BBJ_ALWAYS;
block->bbJumpDest = bottomBlock;
#ifdef DEBUG
if (verbose)
{
printf("\nConvert bbJumpKind of " FMT_BB " to BBJ_ALWAYS to bottomBlock " FMT_BB "\n", block->bbNum,
bottomBlock->bbNum);
}
#endif // DEBUG
}
else
{
#ifdef DEBUG
if (verbose)
{
printf("\nConvert bbJumpKind of " FMT_BB " to BBJ_NONE\n", block->bbNum);
}
#endif // DEBUG
JITDUMP("\nConvert bbJumpKind of " FMT_BB " to BBJ_NONE\n", block->bbNum);
block->bbJumpKind = BBJ_NONE;
}
}

// Update profile weight for callee blocks, if we didn't do it already.
if (pInlineInfo->profileScaleState == InlineInfo::ProfileScaleState::KNOWN)
{
continue;
}

// If we were unable to compute a scale for some reason, then
// try to do something plausible. Entry/exit blocks match call
// site, internal blocks scaled by half; all rare blocks left alone.
//
if (!block->isRunRarely())
{
block->inheritWeightPercentage(iciBlock, inheritWeight ? 100 : 50);
}

inheritWeight = false;
}

// Insert inlinee's blocks into inliner's block list.
Expand Down
Loading

0 comments on commit a4b0a03

Please sign in to comment.