-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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: don't create degenerate flow in fgReplaceJumpTarget
#99509
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -662,6 +662,8 @@ void Compiler::fgReplaceJumpTarget(BasicBlock* block, BasicBlock* oldTarget, Bas | |
|
||
if (block->FalseEdgeIs(oldEdge)) | ||
{ | ||
// Branch was degenerate, simplify it first | ||
// | ||
// fgRemoveRefPred returns nullptr for BBJ_COND blocks with two flow edges to target | ||
fgRemoveConditionalJump(block); | ||
assert(block->KindIs(BBJ_ALWAYS)); | ||
|
@@ -671,10 +673,7 @@ void Compiler::fgReplaceJumpTarget(BasicBlock* block, BasicBlock* oldTarget, Bas | |
// fgRemoveRefPred should have removed the flow edge | ||
fgRemoveRefPred(oldEdge); | ||
assert(oldEdge->getDupCount() == 0); | ||
|
||
// TODO-NoFallThrough: Proliferate weight from oldEdge | ||
// (as a quirk, we avoid doing so for the true target to reduce diffs for now) | ||
FlowEdge* const newEdge = fgAddRefPred(newTarget, block); | ||
FlowEdge* const newEdge = fgAddRefPred(newTarget, block, oldEdge); | ||
|
||
if (block->KindIs(BBJ_ALWAYS)) | ||
{ | ||
|
@@ -684,24 +683,48 @@ void Compiler::fgReplaceJumpTarget(BasicBlock* block, BasicBlock* oldTarget, Bas | |
{ | ||
assert(block->KindIs(BBJ_COND)); | ||
block->SetTrueEdge(newEdge); | ||
|
||
if (oldEdge->hasLikelihood()) | ||
{ | ||
newEdge->setLikelihood(oldEdge->getLikelihood()); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
assert(block->FalseTargetIs(oldTarget)); | ||
FlowEdge* const oldEdge = block->GetFalseEdge(); | ||
|
||
if (block->TrueEdgeIs(oldEdge)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused by this check here. If a block's true and false edges are the same, then shouldn't the condition There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, good point. |
||
{ | ||
// Branch was degenerate | ||
// | ||
// fgRemoveRefPred returns nullptr for BBJ_COND blocks with two flow edges to target | ||
fgRemoveConditionalJump(block); | ||
assert(block->KindIs(BBJ_ALWAYS)); | ||
assert(block->TargetIs(oldTarget)); | ||
} | ||
|
||
// fgRemoveRefPred should have removed the flow edge | ||
fgRemoveRefPred(oldEdge); | ||
assert(oldEdge->getDupCount() == 0); | ||
FlowEdge* const newEdge = fgAddRefPred(newTarget, block, oldEdge); | ||
block->SetFalseEdge(newEdge); | ||
|
||
if (block->KindIs(BBJ_ALWAYS)) | ||
{ | ||
block->SetTargetEdge(newEdge); | ||
} | ||
else | ||
{ | ||
assert(block->KindIs(BBJ_COND)); | ||
block->SetFalseEdge(newEdge); | ||
} | ||
} | ||
|
||
if (block->GetFalseEdge() == block->GetTrueEdge()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the check. |
||
{ | ||
// Block became degenerate, simplify | ||
// | ||
fgRemoveConditionalJump(block); | ||
assert(block->KindIs(BBJ_ALWAYS)); | ||
assert(block->TargetIs(newTarget)); | ||
} | ||
|
||
break; | ||
|
||
case BBJ_SWITCH: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're here, could you please remove this comment about
fgRemoveRefPred
returning nullptr? The new version of it that takes in a flow edge doesn't return anything. Thanks!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep.