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: don't create degenerate flow in fgReplaceJumpTarget #99509

Merged
merged 2 commits into from
Mar 11, 2024

Conversation

AndyAyersMS
Copy link
Member

@AndyAyersMS AndyAyersMS commented Mar 11, 2024

Detect if the update has created degenerate BBJ_COND flow, and simplify. Also symmetrize the true/false cases.

Fixes #48609.

Also fixes some issues seen in enhanced likelihood checking.

Diffs

Detect if the update has created degenerate BBJ_COND flow, and simplify.
Also symmetrize the true/false cases.

Fixes dotnet#48609.

Also fixes some issues seen in enhanced likelhood checking.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 11, 2024
@AndyAyersMS
Copy link
Member Author

@amanasifkhalid PTAL
cc @dotnet/jit-contrib

@@ -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
Copy link
Member

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!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep.

}
}
else
{
assert(block->FalseTargetIs(oldTarget));
FlowEdge* const oldEdge = block->GetFalseEdge();

if (block->TrueEdgeIs(oldEdge))
Copy link
Member

Choose a reason for hiding this comment

The 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 if (block->TrueTargetIs(oldTarget)) above be true, making this code unreachable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, good point.

}

if (block->GetFalseEdge() == block->GetTrueEdge())
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to check if block is still a BBJ_COND here before calling GetFalseEdge/GetTrueEdge. If we converted it to a BBJ_ALWAYS above, this will assert.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added the check.

Copy link
Member

@amanasifkhalid amanasifkhalid left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! I'm curious to see what the diffs look like from this.

}

if (block->KindIs(BBJ_COND) && (block->GetFalseEdge() == block->GetTrueEdge()))
Copy link
Member

Choose a reason for hiding this comment

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

I noticed that we tend to compare the true/false edges with TrueEdgeIs. I'm planning on modifying fgReplaceJumpTarget in an upcoming PR, so I'll fix this then.

@AndyAyersMS
Copy link
Member Author

Diffs don't look too bad. Seems to be mostly layout changes (not surprising) and all that that entails.

@AndyAyersMS AndyAyersMS merged commit 9d56a4c into dotnet:main Mar 11, 2024
127 of 129 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid generating degenerate flow during redundant branch optimization
2 participants