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 delegate loads during inlining #109715

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

Conversation

MichalPetryka
Copy link
Contributor

@MichalPetryka MichalPetryka commented Nov 12, 2024

Propagate delegate loads from static readonly by value when inlining to avoid spilling them.

Alternative of #108579, needed for #109679.

@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 12, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Nov 12, 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 -dependsOn 109679

@MichalPetryka
Copy link
Contributor Author

@MihuBot -dependsOn 109679

@MichalPetryka
Copy link
Contributor Author

@MihuBot

@EgorBo
Copy link
Member

EgorBo commented Nov 12, 2024

Can you explain why this limits static readonly propagation to only delegates?

@MichalPetryka
Copy link
Contributor Author

Can you explain why this limits static readonly propagation to only delegates?

As seen in #108579, propagating everything leads to regressions due to CSE not being able to deduplicate all the new loads. This is not as much of an issue for delegates since those are usually single use and the benefit from better inlining of them outweighs any missed cases of duplicated loads.

@EgorBo
Copy link
Member

EgorBo commented Nov 12, 2024

As seen in #108579, propagating everything leads to regressions due to CSE not being able to deduplicate all the new loa

I don't see how that couldn't be an issue with delegates, e.g.

void Foo(delegate o, bool condition)
{
    if (condition)
    {
        use1(o);
    }
    else
    {
        use2(o);
    }
}

in this case CSE won't be able to handle it, so you'd create two indirs here, not sure it's a big problem just FYI.

I am not against this change, just that the diffs are quite big and we need to inspect them rather than blaming inliner. Let's see the SPMI diffs.

Also, didn't we agreed that we shouldn't touch impIsInvariant in Discord? And use the whatever way typeof() is propagated?

@MichalPetryka
Copy link
Contributor Author

I don't see how that couldn't be an issue with delegates

The idea is that all nullchecks will be folded away while calls will be removed by #109679 so only other operations might end up with duplicated loads but those should be more rare.

Also, didn't we agreed that we shouldn't touch impIsInvariant in Discord? And use the whatever way typeof() is propagated?

We agreed on only putting it in impIsInvariant and not GenTree::IsInvariant. impIsInvariant itself is only used in one place in code currently, the arg propagation.

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.

2 participants