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: removed unneeded throw helper blocks #95379

Merged
merged 7 commits into from
Dec 5, 2023

Conversation

AndyAyersMS
Copy link
Member

Various optimizations can happen between the time the throw helper blocks are first requested (morph) and finally used (codegen). Prune away ones that aren't needed during the stack level setter.

Fixes #93948.

Various optimizations can happen between the time the throw helper blocks
are first requested (morph) and finally used (codegen). Prune away ones
that aren't needed during the stack level setter.

Fixes dotnet#93948.
@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 Nov 29, 2023
@ghost ghost assigned AndyAyersMS Nov 29, 2023
@ghost
Copy link

ghost commented Nov 29, 2023

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

Issue Details

Various optimizations can happen between the time the throw helper blocks are first requested (morph) and finally used (codegen). Prune away ones that aren't needed during the stack level setter.

Fixes #93948.

Author: AndyAyersMS
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@AndyAyersMS
Copy link
Member Author

Diffs

For code size this is pure goodness, but the TP impact is a bit high. Some possible mitigations:

  • there's not much benefit on min opts so we can do some of this more selectively (only if required)
  • the caching done by fgFindExcptnTarget is likely not that effective, seems like we should just keep a full hash table. Want to verify this is the big extra cost first.

@AndyAyersMS
Copy link
Member Author

Also what I'm doing likely won't work for SCK_FAIL_FAST but we don't seem to be using it? It is easy enough to just always keep these if they are pre-generated.

#if !FEATURE_FIXED_OUT_ARGS
// Set throw blocks incoming stack depth for x86.
if (throwHelperBlocksUsed && !framePointerRequired)
if (throwHelperBlocksUsed && node->OperMayThrow(comp))
Copy link
Member

Choose a reason for hiding this comment

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

Since GTF_CALL and GTF_EXCEPT are up-to-date and overapproximations here you can optimize TP with this trick:

if (((*use)->gtFlags & (GTF_EXCEPT | GTF_CALL)) == 0)
{
assert(!(*use)->OperMayThrow(m_compiler));
return use;
}
if (!(*use)->OperMayThrow(m_compiler))
{
return use;
}

@AndyAyersMS
Copy link
Member Author

AndyAyersMS commented Dec 1, 2023

TP looking okayish now (Diffs), realized the stack level setter was disabled for mac arm64, so enabled it there.

As part of this I will also close out #42673.

Final Diffs. If we could merge all this new analysis into lower we might be able to shave off some TP, but that seems more complicated. Since this phase previously did not run for osx-arm64 we can see the overall TP hit is around 0.5% in minopts and 0.2% when optimizing.

@AndyAyersMS
Copy link
Member Author

Should be ready for final review.

FYI @dotnet/jit-contrib

@AndyAyersMS AndyAyersMS marked this pull request as ready for review December 1, 2023 03:41
Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

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

Minor notes


typedef JitHashTable<AddCodeDscKey, AddCodeDscKey, AddCodeDsc*> AddCodeDscMap;

AddCodeDscMap* fgAddCodeDscMap;
Copy link
Member

Choose a reason for hiding this comment

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

Minor, but maybe you should follow the pattern set by GetBlockToEHPreds and many similar functions, to have a:

AddCodeDscMap* GetAddCodeDscMap()
{
    if (fgAddCodeDscMap == nullptr)
    {
         fgAddCodeDscMap = new (getAllocator(CMK_Unknown)) AddCodeDscMap(getAllocator(CMK_Unknown));
    }
    return fgAddCodeDscMap;
}

Instead of having the allocation within fgAddCodeRef

}
else
{
// assert(((node->gtFlags & GTF_CALL) != 0) || !node->OperMayThrow(comp));
Copy link
Member

Choose a reason for hiding this comment

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

Remove or enable

@AndyAyersMS
Copy link
Member Author

SPMI failures are known bad contexts for OSX. Ignoring.

@AndyAyersMS AndyAyersMS merged commit 829524b into dotnet:main Dec 5, 2023
124 of 129 checks passed
tomeksowi added a commit to tomeksowi/runtime that referenced this pull request Dec 15, 2023
This fixes broken CLR tests after dotnet#95379

Co-authored-by: Dong-Heon Jung <clamp03@gmail.com>
AndyAyersMS pushed a commit that referenced this pull request Dec 15, 2023
This fixes broken CLR tests after #95379

Co-authored-by: Dong-Heon Jung <clamp03@gmail.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jan 4, 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: clean up unused throw helpers
3 participants