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

Add constprop handling for typeof(T) == typeof(Foo) #84224

Merged
merged 4 commits into from Apr 3, 2023

Conversation

MichalStrehovsky
Copy link
Member

The pattern typeof(T) == typeof(Foo) is a common way to do generic specialization in C#. Since we operate on instantiated code, we should be able to optimize this in many situations. Adding support for this in constprop.

RyuJIT would already handle this, but the problem is that if we don't handle this in IL scanning, we might have expanded the whole program view graph too much and it's hard to get rid of side effects of that. The added test shows one of such examples (we introduce an extra "used" virtual slot that is impossible to get rid of after the fact).

Saves 0.5% on BasicMinimalApi.

Cc @dotnet/ilc-contrib

The pattern `typeof(T) == typeof(Foo)` is a common way to do generic specialization in C#. Since we operate on instantiated code, we should be able to optimize this in many situations. Adding support for this in constprop.

RyuJIT would already handle this, but the problem is that if we don't handle this in IL scanning, we might have expanded the whole program view graph too much and it's hard to get rid of side effects of that. The added test shows one of such examples (we introduce an extra "used" virtual slot that is impossible to get rid of after the fact).

Saves 0.5% on BasicMinimalApi.
@ghost
Copy link

ghost commented Apr 2, 2023

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

Issue Details

The pattern typeof(T) == typeof(Foo) is a common way to do generic specialization in C#. Since we operate on instantiated code, we should be able to optimize this in many situations. Adding support for this in constprop.

RyuJIT would already handle this, but the problem is that if we don't handle this in IL scanning, we might have expanded the whole program view graph too much and it's hard to get rid of side effects of that. The added test shows one of such examples (we introduce an extra "used" virtual slot that is impossible to get rid of after the fact).

Saves 0.5% on BasicMinimalApi.

Cc @dotnet/ilc-contrib

Author: MichalStrehovsky
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

LGTM!

@jkotas jkotas merged commit afcfc4b into dotnet:main Apr 3, 2023
119 checks passed
@MichalStrehovsky MichalStrehovsky deleted the typeofconstprop branch April 3, 2023 13:32
@dotnet dotnet locked as resolved and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants