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: Avoid check for returns in methods with pinvokes in LSRA #103559

Merged
merged 2 commits into from
Jun 19, 2024

Conversation

jakobbotsch
Copy link
Member

The pinvoke epilog is explicit on all our targets now, so it seems like this code should be unnecessary everywhere (and in any case, should not have been inside very general and very hot newRefPosition).

The pinvoke epilog is explicit on all our targets now, so it seems like
this code should be unnecessary everywhere (and in any case, should not
have been inside very general and very hot `newRefPosition`).
@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 Jun 17, 2024
Copy link
Contributor

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

@jakobbotsch jakobbotsch marked this pull request as ready for review June 17, 2024 11:49
@jakobbotsch
Copy link
Member Author

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

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Jun 17, 2024

Failures are #103577, #103568, #103545, #102370, #102335, #102706

cc @dotnet/jit-contrib PTAL @kunalspathak

A few minor diffs, some good TP improvements.

@kunalspathak
Copy link
Member

The pinvoke epilog is explicit on all our targets now

Can you point to the relevant code? When I search for RBM_PINVOKE_TCB, other than lsrabuild.cpp, I just see it getting used for arm/x86.

@jakobbotsch
Copy link
Member Author

Can you point to the relevant code? When I search for RBM_PINVOKE_TCB, other than lsrabuild.cpp, I just see it getting used for arm/x86.

The pinvoke epilog is inserted as regular IR in lowering:

//------------------------------------------------------------------------
// InsertPInvokeMethodEpilog: Code that needs to be run when exiting any method
// that has PInvoke inlines. This needs to be inserted any place you can exit the
// function: returns, tailcalls and jmps.
//
// Arguments:
// returnBB - basic block from which a method can return
// lastExpr - GenTree of the last top level stmnt of returnBB (debug only arg)
//
// Return Value:
// Code tree to perform the action.
//
void Lowering::InsertPInvokeMethodEpilog(BasicBlock* returnBB DEBUGARG(GenTree* lastExpr))

I suspect the code I am removing here exists because at some point the pinvoke epilog was implicitly generated as part of epilog codegen (or perhaps GT_RETURN codegen). But since it is explicitly represented in IR today LSRA should already be handling the conflicts that may arise by normal means.

@kunalspathak
Copy link
Member

Does that mean we do not need RBM_PINVOKE_FRAME and need RBM_PINVOKE_TCB only for x86/arm?

@jakobbotsch
Copy link
Member Author

Does that mean we do not need RBM_PINVOKE_FRAME and need RBM_PINVOKE_TCB only for x86/arm?

REG_PINVOKE_FRAME is still used. It doesn't look like RBM_PINVOKE_FRAME has uses, but I guess it's nice to be consistent about making the mask versions available.

Both are only used in x86/arm32, so the definitions outside could be removed. Do you want me to do that as part of this PR?

@kunalspathak
Copy link
Member

REG_PINVOKE_FRAME is still used. It doesn't look like RBM_PINVOKE_FRAME has uses, but I guess it's nice to be consistent about making the mask versions available.

The only use I see for REG_PINVOKE_FRAME is this, which is for x86/arm, so we can just keep it for x86/arm and remove it from other targets.

#if defined(TARGET_X86) || defined(TARGET_ARM)
// The x86 and arm32 CORINFO_HELP_INIT_PINVOKE_FRAME helpers have a custom calling convention.
case WellKnownArg::PInvokeFrame:
return REG_PINVOKE_FRAME;

After this PR, there is no usage of RBM_PINVOKE_FRAME, so can get rid of that as well.

Both are only used in x86/arm32, so the definitions outside could be removed. Do you want me to do that as part of this PR?

Yes, that will be good.

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Jun 18, 2024

After this PR, there is no usage of RBM_PINVOKE_FRAME, so can get rid of that as well.

There are plenty of other cases where we have REG_X and RBM_X where only one is used, but where both are defined. E.g. REG_EXCEPTION_OBJECT (unused) vs RBM_EXCEPTION_OBJECT (used), REG_R2R_INDIRECT_PARAM (used) vs RBM_R2R_INDIRECT_PARAM (unused), etc.

Like I mentioned above I think we should consistently define both versions, so I don't think we should remove the RBM version. But I can remove the definitions outside x86/arm32.

@kunalspathak
Copy link
Member

Like I mentioned above I think we should consistently define both versions, so I don't think we should remove the RBM version. But I can remove the definitions outside x86/arm32.

SGTM

Copy link
Member

@kunalspathak kunalspathak 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!

@jakobbotsch jakobbotsch merged commit a5c1c9f into dotnet:main Jun 19, 2024
103 of 107 checks passed
@jakobbotsch jakobbotsch deleted the lsra-avoid-pinvoke-check branch June 19, 2024 14:09
@github-actions github-actions bot locked and limited conversation to collaborators Jul 20, 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