Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Set edge likelihoods during patchpoint transformation #97897

Merged
merged 6 commits into from
Feb 5, 2024
Merged
Changes from 2 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
17 changes: 15 additions & 2 deletions src/coreclr/jit/patchpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,21 @@ class PatchpointTransformer

helperBlock->SetFlags(BBF_BACKWARD_JUMP | BBF_NONE_QUIRK);

compiler->fgAddRefPred(helperBlock, block);
compiler->fgAddRefPred(remainderBlock, helperBlock);
FlowEdge* const falseEdge = compiler->fgAddRefPred(helperBlock, block);
FlowEdge* const trueEdge = compiler->fgGetPredForBlock(remainderBlock, block);

if (trueEdge->hasLikelihood())
{
falseEdge->setLikelihood(1.0 - trueEdge->getLikelihood());
}
else
{
trueEdge->setLikelihood(0.5);
falseEdge->setLikelihood(0.5);
Copy link
Member

Choose a reason for hiding this comment

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

The test actually passing should be very rare (I believe the threshold is 1/10000). Also, isn't trueEdge always going to be the BBJ_ALWAYS edge inserted by fgSplitBlockAtBeginning above, so the check here is a bit meaningless?

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, isn't trueEdge always going to be the BBJ_ALWAYS edge inserted by fgSplitBlockAtBeginning above, so the check here is a bit meaningless?

Ah you're right, so trueEdge should always have an edge likelihood here. I'll remove the branch.

The test actually passing should be very rare (I believe the threshold is 1/10000).

Is there any value to being more precise than 0.1/0.9 for trueEdge/falseEdge's likelihoods?

Copy link
Member

Choose a reason for hiding this comment

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

In tier0? Doubtful. Also 1/10000 is not entirely accurate since I believe multiple patchpoints share the counter, but @AndyAyersMS can correct me if I'm wrong...

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 see below this snippet that helperBlock inherits 1% of block's weight; should we have the edge likelihoods match that? So trueEdge is 0.99, and falseEdge is 0.01.

Copy link
Member

@jakobbotsch jakobbotsch Feb 2, 2024

Choose a reason for hiding this comment

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

Makes sense to me to be consistent with that. On further look it looks like TC_OnStackReplacement_InitialCounter is 1000. Not sure if the mismatch is intentional or not; in a way, the most accurate guess we could make is probably 1 / <that value>, but feel free to stick with the 1% here.

Copy link
Member

Choose a reason for hiding this comment

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

Overall it probably doesn't matter since (at least for now) we only have patchpoints in unoptimized code. I guess I'd go with the precedent already there and use the 0.99/0.01 split.

}

FlowEdge* const newEdge = compiler->fgAddRefPred(remainderBlock, helperBlock);
newEdge->setLikelihood(1.0);

// Update weights
remainderBlock->inheritWeight(block);
Expand Down
Loading