Skip to content

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.
@ghost ghost 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

{
// Branch was degenerate, simplify it first
//
// fgRemoveRefPred returns nullptr for BBJ_COND blocks with two flow edges to target
Copy link
Contributor

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.

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

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

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
Contributor

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
Contributor

@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
Contributor

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.

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