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: Remove CallArg::m_tmpNum #104429

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Jul 4, 2024

The JIT currently has two places where it may introduce temps during call args morphing:

  1. Directly during fgMorphArgs as part of making struct copies for some struct args, like implicit byref args and other struct args requiring to be of LCL_VAR shape
  2. During EvalArgsToTemps as part of making sure evaluation order is maintained while we get the call into the right shape with registers

To make this work we have CallArg::m_tmpNum that communicates the local from 1 to 2; the responsibility of creating the actual LCL_VAR node to put in the late argument list was left to EvalArgsToTemps while fgMorphArgs would just change the early setup node to a store into the temporary.

This PR changes it so that 1 directly introduces the right late node when it creates its temporary. That is, it puts the call argument into the right shape immediately and avoids relying on EvalArgsToTemps to create the local node in the late list.

The benefit of that is that we no longer need to communicate the temporary as part of every CallArg. However, the motivation here is something else: as part of #104370 we may have arguments that need multiple temporaries to copy, so having things working in this way introduces complications for that.

No diffs are expected.

Before this change the JIT has two places where it may introduce temps
during call args morphing:
1. Directly during `fgMorphArgs` as part of making struct copies for
   some struct args, like implicit byref args and other struct args
   requiring to be of `LCL_VAR` shape
2. During `EvalArgsToTemps` as part of making sure evaluation order is
   maintained while we get the call into the right shape with registers

To make this work we have `CallArg::m_tmpNum` that communicates the
local from 1 to 2; the responsibility of creating the actual `LCL_VAR`
node to put in the late argument list was left to `EvalArgsToTemps`
while `fgMorphArgs` would just change the early setup node to a store
into the temporary.

This PR changes it so that 1 directly introduces the right late node
when it creates its temporary. That is, it puts the call argument into
the right shape immediately and avoids relying on `EvalArgsToTemps` to
create the local node in the late list.

The benefit of that is that we no longer need to communicate the
temporary as part of every `CallArg`. However, the motivation here is
something else: as part of dotnet#104370 we may have arguments that need
multiple temporaries to copy, so having things working in this way
introduces complications for that.
@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 Jul 4, 2024
Copy link
Contributor

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

Comment on lines -877 to -883

if (argx == nullptr)
{
// Should only happen if remorphing in which case we do not need to
// make a decision about temps.
continue;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

ArgsComplete is not called during remorphing, so the code should be dead.

@@ -3264,29 +3222,31 @@ void Compiler::fgMakeOutgoingStructArgCopy(GenTreeCall* call, CallArg* arg)
assert(!fgGlobalMorph);
}

call->gtArgs.SetNeedsTemp(arg);
Copy link
Member Author

Choose a reason for hiding this comment

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

This was previously done in ArgsComplete (the code in the GTF_ASG case), but it makes more sense just to do it immediately when we introduce the temp.

@jakobbotsch jakobbotsch marked this pull request as ready for review July 4, 2024 14:47
@jakobbotsch
Copy link
Member Author

jakobbotsch commented Jul 4, 2024

cc @dotnet/jit-contrib PTAL @EgorBo

No diffs, some minor TP improvements.

Some spurious diffs in win-arm64 NAOT; seems likely to be from #104282, I opened #104441 about it.

@jakobbotsch
Copy link
Member Author

/azp run runtime-coreclr superpmi-diffs

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jakobbotsch
Copy link
Member Author

Ping @EgorBo

@jakobbotsch jakobbotsch merged commit 7029008 into dotnet:main Jul 10, 2024
107 checks passed
@jakobbotsch jakobbotsch deleted the callarg-remove-tmp-num branch July 10, 2024 10:52
matouskozak added a commit to matouskozak/runtime that referenced this pull request Jul 11, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 10, 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