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: Add post-phase validation of DFS tree #95682

Merged
merged 7 commits into from
Dec 8, 2023

Conversation

jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Dec 6, 2023

Add a post-phase check that validates that the DFS tree matches the current flow graph when it is non-null.

Add a fgInvalidateDfsTree() that invalidates the DFS tree and derived annotations on it (dominators and loops). We invalidate after RBO, which is the last point we expect to make use of the flow graph information.

Fix #95652

Add a post-phase check that validates that the DFS tree matches the
current flow graph when it is non-null.

Add a `fgInvalidateDfsTree()` that invalidates the DFS tree and derived
annotations on it (dominators and loops). We invalidate after RBO, which
is the last point we expect to make use of the flow graph information.

Compute new DFS and loops as part of loop unrolling to make the DFS tree
correct after this point too. Some TP regressions are expected due to
this.

To sum up we now keep this information valid from loop finding until
RBO.

Fix dotnet#95652
@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 Dec 6, 2023
@ghost ghost assigned jakobbotsch Dec 6, 2023
@ghost
Copy link

ghost commented Dec 6, 2023

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

Issue Details

Add a post-phase check that validates that the DFS tree matches the current flow graph when it is non-null.

Add a fgInvalidateDfsTree() that invalidates the DFS tree and derived annotations on it (dominators and loops). We invalidate after RBO, which is the last point we expect to make use of the flow graph information.

Compute new DFS and loops as part of loop unrolling to make the DFS tree correct after this point too. Some TP regressions are expected due to this.

To sum up we now keep this information valid from loop finding until RBO.

Fix #95652

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

Comment on lines -4950 to -4966
// Assertion prop can do arbitrary statement remorphing, which
// can clone code and disrupt our simpleminded SSA accounting.
//
// So, disable the ssa checks.
//
if (fgSsaValid)
{
JITDUMP("Marking SSA as invalid before assertion prop\n");
fgSsaValid = false;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

@AndyAyersMS The SSA checker is dependent on SSA's dominator tree, which is stale after RBO, so I'm also setting fgSsaValid = false in fgInvalidateDfsTree. It means we no longer check after CSEs, but I suppose that's not a big issue since RBO is really the last user.

Copy link
Member Author

Choose a reason for hiding this comment

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

(Seems like the SSA checker could be switched to iterate the post order of the DFS as well)

Copy link
Member

Choose a reason for hiding this comment

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

Ok by me -- at one point I wanted to keep the SSA checked properties viable longer, but I don't recall why.

@jakobbotsch
Copy link
Member Author

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

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

{
visitor.PreOrderVisit(block);
scv.WalkTree(stmt->GetRootNodePointer(), nullptr);
}
}
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've removed this since fgDomBBcount is not SSA's dom count, and since the new DFS validation would trigger if a (reachable) block was added anyway. Also switched the above to iterate the blocks via the computed post order from the DFS tree.

Comment on lines +6441 to +6465
// The DFS we run is not precise around call-finally, so
// `fgRemoveUnreachableBlocks` can expose newly unreachable blocks
// that we did not uncover during the DFS. If we did remove any
// call-finally blocks then iterate to closure. This is a very rare
// case.
while (true)
{
bool anyCallFinallyPairs = false;
fgRemoveUnreachableBlocks([=, &anyCallFinallyPairs](BasicBlock* block) {
if (!m_dfsTree->Contains(block))
{
anyCallFinallyPairs |= block->isBBCallAlwaysPair();
return true;
}

return false;
});

if (!anyCallFinallyPairs)
{
break;
}

m_dfsTree = fgComputeDfs();
}
Copy link
Member Author

@jakobbotsch jakobbotsch Dec 8, 2023

Choose a reason for hiding this comment

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

Sadly even with the more precise EH treatment we do not get around this issue, so I've had to add this iteration to closure to make sure the validation passes in cases where removing a callfinally/always pair results in new unreachable blocks (without the validation it would just result in a bit conservative behavior -- considering some blocks reachable that aren't). I only saw one assertion in all of our collections, so at least TP wise it does not seem like an issue.

@jakobbotsch
Copy link
Member Author

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

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jakobbotsch jakobbotsch marked this pull request as ready for review December 8, 2023 21:37
@jakobbotsch
Copy link
Member Author

The Fuzzlyn failure repros on main too, will open an issue for that.

cc @dotnet/jit-contrib PTAL @AndyAyersMS @BruceForstall

No diffs.

@jakobbotsch jakobbotsch merged commit ba1d799 into dotnet:main Dec 8, 2023
193 of 196 checks passed
@jakobbotsch jakobbotsch deleted the validate-dfs branch December 8, 2023 23:47
@github-actions github-actions bot locked and limited conversation to collaborators Jan 8, 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.

JIT: Validate DFS tree in post-phase checks
3 participants