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

Propagate static readonly loads by value during inlining #108579

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

MichalPetryka
Copy link
Contributor

@MichalPetryka MichalPetryka commented Oct 6, 2024

Makes the JIT propagate invariant loads without side effects when inlining, preventing the JIT from spilling them.

Contains a hack to avoid static readonly args boosting inliner profitability.

@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 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 6, 2024
Copy link
Contributor

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

@MichalPetryka
Copy link
Contributor Author

@MihuBot

MichalPetryka added a commit to MichalPetryka/runtime that referenced this pull request Oct 7, 2024
Alternative to spilling changes in dotnet#108579
everyofflineuser

This comment was marked as spam.

AndyAyersMS pushed a commit that referenced this pull request Oct 22, 2024
Alternative to spilling changes in #108579

Co-authored-by: Egor Bogatov <[email protected]>
@MichalPetryka
Copy link
Contributor Author

@MihuBot

@MichalPetryka
Copy link
Contributor Author

@MihuBot

src/coreclr/jit/gentree.cpp Outdated Show resolved Hide resolved
@MichalPetryka
Copy link
Contributor Author

@MihuBot

@MichalPetryka
Copy link
Contributor Author

Okay, I looked into what's going on with inliner inlining more stuff here, apparently the reduced spilling on static readonly args which causes less locals to be used makes it reduce the profitability multiplier less which causes more inlining.
Another interesting part is that the JIT now sees loads of fields from static readonlys as side-effect free.

@MichalPetryka MichalPetryka changed the title Avoid spilling loads of static readonly variables Propagate static readonly loads by value during inlining Oct 23, 2024
MichalPetryka added a commit to MichalPetryka/runtime that referenced this pull request Oct 23, 2024
@MichalPetryka
Copy link
Contributor Author

@MihuBot -dependsOn 109716

@JulieLeeMSFT
Copy link
Member

@AndyAyersMS will review this PR.

@AndyAyersMS
Copy link
Member

Can you add a comment up top to explain the motivation for this change?

Also, please help me understand why we should do this during inlining. The main goal of inlining's forward sub is to recognize further inlining opportunities and/or get a better handle on the cost of the inlinee.

@MichalPetryka
Copy link
Contributor Author

Can you add a comment up top to explain the motivation for this change?

Also, please help me understand why we should do this during inlining. The main goal of inlining's forward sub is to recognize further inlining opportunities and/or get a better handle on the cost of the inlinee.

The goal here was to let #109679 work across methods, but this leads to bad diffs from duplicated loads that CSE can't handle. I opened #109715 as an alternative to limit it to delegates only cause I'm not sure if there's any way to block the bad cases here...

@AndyAyersMS
Copy link
Member

Can you add a comment up top to explain the motivation for this change?
Also, please help me understand why we should do this during inlining. The main goal of inlining's forward sub is to recognize further inlining opportunities and/or get a better handle on the cost of the inlinee.

The goal here was to let #109679 work across methods, but this leads to bad diffs from duplicated loads that CSE can't handle. I opened #109715 as an alternative to limit it to delegates only cause I'm not sure if there's any way to block the bad cases here...

I think we should approach #109679 differently. Instead of trying to pull all this off during importation and inlining, I would like to see us focus on refactoring the inliner so it can be invoked as a utility in later phases and then rely on normal forward propagation of facts to enable new inlining in cases like these.

I realize that:

  • what I'm proposing here is to solve a harder problem in order to make this one easier;
  • I'm not entirely sure yet how to go about the necessary inliner refactoring;
  • I have reasons to believe it will be somewhat tricky;
  • I likely won't have time to seriously consider or guide anyone through it during .NET 10

So this would likely mean shelving all this work until sometime later next year.

If you want to keep working in this area a good starter project might be to move the delegate invoke expansion earlier in the jit; that might be enough to unblock escape analysis of the delegate in some cases.

I might be willing to reconsider if you strongly feel that we should consider following through on your current plans and can show some compelling data on the improvements this could bring.

@MichalPetryka
Copy link
Contributor Author

MichalPetryka commented Nov 21, 2024

Can you add a comment up top to explain the motivation for this change?
Also, please help me understand why we should do this during inlining. The main goal of inlining's forward sub is to recognize further inlining opportunities and/or get a better handle on the cost of the inlinee.

The goal here was to let #109679 work across methods, but this leads to bad diffs from duplicated loads that CSE can't handle. I opened #109715 as an alternative to limit it to delegates only cause I'm not sure if there's any way to block the bad cases here...

I think we should approach #109679 differently. Instead of trying to pull all this off during importation and inlining, I would like to see us focus on refactoring the inliner so it can be invoked as a utility in later phases and then rely on normal forward propagation of facts to enable new inlining in cases like these.

I realize that:

  • what I'm proposing here is to solve a harder problem in order to make this one easier;
  • I'm not entirely sure yet how to go about the necessary inliner refactoring;
  • I have reasons to believe it will be somewhat tricky;
  • I likely won't have time to seriously consider or guide anyone through it during .NET 10

So this would likely mean shelving all this work until sometime later next year.

If you want to keep working in this area a good starter project might be to move the delegate invoke expansion earlier in the jit; that might be enough to unblock escape analysis of the delegate in some cases.

I might be willing to reconsider if you strongly feel that we should consider following through on your current plans and can show some compelling data on the improvements this could bring.

Could we move all discussion regarding #109679 to its comments? I'd prefer to reply on the PR in question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants