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: Use successor edges instead of block targets for remaining block kinds #98993

Merged
merged 18 commits into from
Feb 28, 2024

Conversation

amanasifkhalid
Copy link
Member

Part of #93020. Replaces BasicBlock::bbTarget/bbFalseTarget/bbTrueTarget with FlowEdge* members.

@ghost ghost assigned amanasifkhalid Feb 27, 2024
@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 Feb 27, 2024
@ghost
Copy link

ghost commented Feb 27, 2024

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

Part of #93020. Replaces BasicBlock::bbTarget/bbFalseTarget/bbTrueTarget with FlowEdge* members.

Author: amanasifkhalid
Assignees: amanasifkhalid
Labels:

area-CodeGen-coreclr

Milestone: -

@amanasifkhalid
Copy link
Member Author

/azp run runtime-coreclr outerloop, runtime-coreclr jitstress, runtime-coreclr libraries-jitstress, Fuzzlyn

Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@amanasifkhalid
Copy link
Member Author

/azp run runtime-coreclr outerloop, runtime-coreclr jitstress, runtime-coreclr libraries-jitstress, Fuzzlyn

Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@amanasifkhalid
Copy link
Member Author

cc @dotnet/jit-contrib, @AndyAyersMS PTAL. Sorry for the large change; here are a few notes that will hopefully expedite reviews:

  • This is a no-diff change. There is some pretty big MinOpts TP impact on x86, though that's only in coreclr_tests, so I imagine it's not the norm. I can dig into that, if you'd like.
  • I had to move the definition of FlowEdge to above the definition of BasicBlock in block.h, hence the large diffs in that file.
  • Most of the changes are quite repetitive (i.e. replacing SetTarget with SetTargetEdge, passing new FlowEdge pointers to SetKindAndTargetEdge, etc.). I'll mention a few interesting cases below.
  • In impImportLeave, we previously would set up block targets as soon as we could, and then set up the successor edge after each if-elseif-else statement. Now, we leave bbTargetEdge uninitialized until we create the edge after each if-elseif-else statement. This method is hard to read, so I thought I'd point out the edge creation behavior should be the same here.
  • I touched on this offline, but our edge likelihood logic in fgAddRefPred when initializingPreds=true is probably wrong now: We need to call NumSucc to calculate the edge likelihood, and NumSucc compares bbTrueEdge and bbFalseEdge for BBJ_COND blocks to determine the true number of successors. Because those edge pointers aren't set yet when initializing preds, we're technically reading uninitialized memory. As far as I know, the worst this can do is cause us to calculate incorrect likelihoods for BBJ_COND blocks, and we aren't asserting that likelihoods are sensible yet. I think the simplest fix is to move these edge likelihood calculations to fgLinkBasicBlocks (and wherever else we call fgAddRefPred<initializingPreds = true>. I can do that in a follow-up PR.
  • There are now two versions of BasicBlock::SetCond. The "normal" version initializes the true and false edges, and is currently used in all cases except one. The other version only sets the true edge, and allows us to set the false edge later. I added this latter version to facilitate lowering switch blocks into jump sequences; our current implementation of that defers setting the false target of each conditional block until a later iteration of a loop. I'm open to suggestions for refactoring this logic, but I found the approach with the least amount of churn was to simply allow deferring the false edge's initialization.

JitStress failure is #98971. SPMI failure is a timeout.

@amanasifkhalid amanasifkhalid marked this pull request as ready for review February 27, 2024 21:12
Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

This was pleasantly mechanical to review. Nice work!

My recent on likelihood checking PR will clash. Yours should go first.

@@ -194,7 +194,7 @@ inline AssertionIndex GetAssertionIndex(unsigned index)

class AssertionInfo
{
// true if the assertion holds on the bbNext edge instead of the bbTarget edge (for GT_JTRUE nodes)
// true if the assertion holds on the false edge instead of the true edge (for GT_JTRUE nodes)
Copy link
Member

Choose a reason for hiding this comment

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

We should consider renaming the field too, the logical name would be m_isFalseEdgeAssertion but that might mix up whether it's an assertion about the false edge, or a false assertion about an edge. So maybe m_assertionHoldsOnFalseEdge?

But I suggest deferring this until later.

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 have some cleanup tasks planned as a follow-up to this PR. I'll make sure to include the rename; m_assertionHoldsOnFalseEdge sounds good to me.

Comment on lines +171 to +173
fgRemoveRefPred(currentBlock->GetTargetEdge());
FlowEdge* const newEdge = fgAddRefPred(postTryFinallyBlock, currentBlock);

Copy link
Member

Choose a reason for hiding this comment

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

I can already see that this removeRef/addRef/setTarget pattern is super common. Looking forward to us encapsulating this sort of thing in a future PR.

@amanasifkhalid
Copy link
Member Author

My recent on likelihood checking PR will clash. Yours should go first.

Thanks for letting me know -- I'll merge this now.

@amanasifkhalid amanasifkhalid merged commit 40d1c89 into dotnet:main Feb 28, 2024
248 of 261 checks passed
@amanasifkhalid amanasifkhalid deleted the cond-always-succ branch February 28, 2024 03:17
amanasifkhalid added a commit that referenced this pull request Feb 29, 2024
After #98993, the logic for initializing edge likelihoods in fgAddRefPred can potentially read uninitialized memory by calling BasicBlock::NumSucc. Avoid this by moving the edge likelihood logic to fgLinkBasicBlocks, where we can safely and cheaply determine the number of successors. Also, rename AssertionInfo::m_isNextEdgeAssertion based on feedback from #98993.
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 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.

2 participants