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: update tail call IR validity checks #94130

Merged
merged 2 commits into from
Oct 30, 2023

Conversation

AndyAyersMS
Copy link
Member

@AndyAyersMS AndyAyersMS commented Oct 28, 2023

Remove fgCheckStmtAfterTailCall as it did less thorough and less correct checking. We will rely on fgValidateIRForTailCall to sanity check that there is no unexpcted IR after a tail call.

Contributes to #93246.

Adapt `fgValidateIRForTailCall` to use as a utility to verify that the
JIT has not added IR that would make a tail call invalid. Currently all
our cases pass this check so no tail calls are invalidated.

Remove `fgCheckStmtAfterTailCall` as it did less thorough and less
correct checking.

Contributes to dotnet#93246.
@ghost ghost assigned AndyAyersMS Oct 28, 2023
@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 Oct 28, 2023
@ghost
Copy link

ghost commented Oct 28, 2023

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

Issue Details

Adapt fgValidateIRForTailCall to use as a utility to verify that the JIT has not added IR that would make a tail call invalid. Currently all our cases pass this check so no tail calls are invalidated.

Remove fgCheckStmtAfterTailCall as it did less thorough and less correct checking.

Contributes to #93246.

Author: AndyAyersMS
Assignees: AndyAyersMS
Labels:

area-CodeGen-coreclr

Milestone: -

@AndyAyersMS
Copy link
Member Author

AndyAyersMS commented Oct 28, 2023

FYI @dotnet/jit-contrib

No diffs expected.

See #93997 (comment) for context. Once we move return merging earlier, we may end up with a small number of cases where phases between fgAddInternal and morph add code after tail calls, since those blocks are (for a stretch) BBJ_ALWAYS or BBJ_NONE.

TailCallIRValidatorVisitor visitor(this, call);
for (Statement* stmt = compCurStmt; stmt != nullptr; stmt = stmt->GetNextStmt())
for (Statement* stmt = compCurStmt; visitor.IsValid() && (stmt != nullptr); stmt = stmt->GetNextStmt())
{
visitor.WalkTree(stmt->GetRootNodePointer(), nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I think it would be a bit cleaner to return WALK_ABORT on validation failure in the visitor (looks like at least GT_RETURN needs to be fixed) and have early exits for when WalkTree returns that.

@jakobbotsch
Copy link
Member

jakobbotsch commented Oct 28, 2023

Hmm, I just realized this is problematic for explicit tailcalls... We cannot be allowed to invalidate those. Is it possible to have #93997 avoid merging (explicit) tailcall cases instead?

@AndyAyersMS
Copy link
Member Author

Hmm, I just realized this is problematic for explicit tailcalls... We cannot be allowed to invalidate those. Is it possible to have #93997 avoid merging (explicit) tailcall cases instead?

Yes, we can do something like that. I am currently thinking:

  • don't merge any tail call cases in fgAddInternal
  • enhance tail merge to handle returns specially (think you pointed this out this a while back)
  • when we get to morph, if there are any tail call cases, mark the genReturnBB as out of order for RPO, since it may gain preds during morph. So we'll lose any morph assertion prop into genReturnBB but that should be ok.

I can adapt this PR to go back to assertion checking like it was doing before, and drop fgCheckStmtAfterTailCal.

@jakobbotsch
Copy link
Member

That sounds good to me.

@AndyAyersMS AndyAyersMS changed the title JIT: rework tail call IR validity checks JIT: update tail call IR validity checks Oct 28, 2023
@AndyAyersMS
Copy link
Member Author

Revised per above.

@AndyAyersMS
Copy link
Member Author

Failures are known.

@AndyAyersMS
Copy link
Member Author

/azp run runtime-coreclr jitstress

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@AndyAyersMS AndyAyersMS merged commit 7dba9af into dotnet:main Oct 30, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Nov 29, 2023
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