Skip to content
Closed
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17681,6 +17681,9 @@ void Compiler::fgExpandQmarkForCastInstOf(BasicBlock* block, Statement* stmt)

assert(qmark->gtFlags & GTF_QMARK_CAST_INSTOF);

float currBbWeight = block->bbWeight;
float nextBbWeight = (block->bbNext != nullptr) ? block->bbNext->bbWeight : currBbWeight;

// Get cond, true, false exprs for the qmark.
GenTree* condExpr = qmark->gtGetOp1();
GenTree* trueExpr = qmark->gtGetOp2()->AsColon()->ThenNode();
Expand Down Expand Up @@ -17766,11 +17769,18 @@ void Compiler::fgExpandQmarkForCastInstOf(BasicBlock* block, Statement* stmt)
cond1Block->bbJumpDest = remainderBlock;
cond2Block->bbJumpDest = remainderBlock;

// Set the weights; some are guesses.
// Currently, we don't instrument internal blocks, so the only way we can set weights to these blocks
// is to analyze successors and take a guess.
float cond2BlockWeight = 0;
if (currBbWeight > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a comment explaining why the computation makes sense.

I don't think values of 100 and 50 should enter in directly (the scaling should be based entirely on the weights from neighboring blocks and perhaps some ad-hoc guesses which you should call out explicitly).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some comments around (covers 50 value)

{
cond2BlockWeight = min(max(50.0f * nextBbWeight / currBbWeight + 50.0f, 50.0f), 100.0f);
}

asgBlock->inheritWeight(block);
cond1Block->inheritWeight(block);
cond2Block->inheritWeightPercentage(cond1Block, 50);
helperBlock->inheritWeightPercentage(cond2Block, 50);
cond2Block->inheritWeightPercentage(block, (UINT32)cond2BlockWeight);
helperBlock->inheritWeightPercentage(block, 100 - (UINT32)cond2BlockWeight);

// Append cond1 as JTRUE to cond1Block
GenTree* jmpTree = gtNewOperNode(GT_JTRUE, TYP_VOID, condExpr);
Expand Down