KEMBAR78
Add constprop handling for `typeof(T) == typeof(Foo)` by MichalStrehovsky · Pull Request #84224 · dotnet/runtime · GitHub
Skip to content

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
@MichalStrehovsky MichalStrehovsky deleted the typeofconstprop branch April 3, 2023 13:32
@ghost ghost 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.

3 participants