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 "add copies" phase #83310

Merged
merged 4 commits into from
Mar 15, 2023
Merged

Conversation

jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Mar 12, 2023

This phase seems to try to do some ad-hoc live range splitting to improve things in assertion prop, but it almost barely kicks in due to the following checks:

// If locals must be initialized to zero, that initialization counts as a second definition.
// VB in particular allows usage of variables not explicitly initialized.
// Note that this effectively disables this optimization for all local variables
// as C# sets InitLocals all the time starting in Whidbey.
if (!varDsc->lvIsParam && info.compInitMem)
{
continue;
}
// On x86 we may want to add a copy for an incoming double parameter
// because we can ensure that the copy we make is double aligned
// where as we can never ensure the alignment of an incoming double parameter
//
// On all other platforms we will never need to make a copy
// for an incoming double parameter
bool isFloatParam = false;
#ifdef TARGET_X86
isFloatParam = varDsc->lvIsParam && varTypeIsFloating(typ);
#endif
if (!isFloatParam && !varDsc->lvVolatileHint)
{
continue;
}

When it does kick in it seems to overall be a regression (diffs), both in ASM diffs and in TP diffs.
Furthermore, we pay 16 bytes in every LclVarDsc (out of 88) for bookkeeping purposes for this pass, even in MinOpts.

@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 Mar 12, 2023
@ghost ghost assigned jakobbotsch Mar 12, 2023
@ghost
Copy link

ghost commented Mar 12, 2023

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

Issue Details

null

Author: jakobbotsch
Assignees: jakobbotsch
Labels:

area-CodeGen-coreclr

Milestone: -

// Introduce copies for some single-def locals to make them more
// amenable to optimization
//
DoPhase(this, PHASE_OPTIMIZE_ADD_COPIES, &Compiler::optAddCopies);
Copy link
Member

Choose a reason for hiding this comment

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

Remove PHASE_OPTIMIZE_ADD_COPIES from compphases.h ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, good catch, done!

@EgorBo
Copy link
Member

EgorBo commented Mar 12, 2023

Nice wins actually 😄 (except TP on arm32)

@jakobbotsch
Copy link
Member Author

Nice wins actually 😄 (except TP on arm32)

This is likely just an artifact of the decreased size of LclVarDsc, I will push this without the fields removed to see

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Mar 13, 2023

Diffs when the fields are left in, but with the pass itself removed.

cc @dotnet/jit-contrib -- I propose that we remove this phase. The phase itself is overall a regression to have around, both on TP and ASM diffs. In addition it requires 16 bytes in LclVarDsc (out of 88 on x64) that we pay for even in MinOpts.
The phase seems to try to do some ad-hoc live-range splitting before assertion prop, but it almost never kicks in because of these checks:

// If locals must be initialized to zero, that initialization counts as a second definition.
// VB in particular allows usage of variables not explicitly initialized.
// Note that this effectively disables this optimization for all local variables
// as C# sets InitLocals all the time starting in Whidbey.
if (!varDsc->lvIsParam && info.compInitMem)
{
continue;
}
// On x86 we may want to add a copy for an incoming double parameter
// because we can ensure that the copy we make is double aligned
// where as we can never ensure the alignment of an incoming double parameter
//
// On all other platforms we will never need to make a copy
// for an incoming double parameter
bool isFloatParam = false;
#ifdef TARGET_X86
isFloatParam = varDsc->lvIsParam && varTypeIsFloating(typ);
#endif
if (!isFloatParam && !varDsc->lvVolatileHint)
{
continue;
}

The first check there also means it kicks in even less in customer code that doesn't have SkipLocalsInit.

@jakobbotsch jakobbotsch marked this pull request as ready for review March 13, 2023 09:50
@jakobbotsch jakobbotsch merged commit ccefbf9 into dotnet:main Mar 15, 2023
@jakobbotsch jakobbotsch deleted the remove-optAddCopies branch March 15, 2023 10:58
@ghost ghost locked as resolved and limited conversation to collaborators Apr 14, 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