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

Pass exact context to getMethodInfo #88025

Merged
merged 21 commits into from
Jul 3, 2023

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Jun 25, 2023

Basically, it's Andy's patch that he never landed and asked me to (with some modifications).

Closes #88021

bool Test() => EqualityComparer<string>.Default.Equals("str", "str");

New codegen:

; Method Prog:Foo():bool:this
       mov      eax, 1
       ret      
; Total bytes of code: 6

It is also needed for #87847

@ghost ghost assigned EgorBo Jun 25, 2023
@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 Jun 25, 2023
@ghost
Copy link

ghost commented Jun 25, 2023

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

Issue Details

Basically, it's Andy's patch that he never landed and asked me to.

Closes #88021

bool Test() => EqualityComparer<string>.Default.Equals("str", "str");

New codegen:

; Method Prog:Foo():bool:this
       mov      eax, 1
       ret      
; Total bytes of code: 6
Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -

@hez2010
Copy link
Contributor

hez2010 commented Jun 26, 2023

Wow I got some impressive performance improvements in my local benchmark.

But there's still some weird codegen which is unnecessary.

For example:

bool Test() => new Foo(1, "hello", "test") == new Foo(1, "test", "hello");

record struct Foo(int x, string y, string z);

The codegen for Test is

G_M50849_IG01:  ;; offset=0000H
						;; size=0 bbWeight=1.00 PerfScore 0.00
G_M50849_IG02:  ;; offset=0000H
       xor      eax, eax
       je       SHORT G_M50849_IG04
						;; size=4 bbWeight=1.00 PerfScore 1.25
G_M50849_IG03:  ;; offset=0004H
       xor      eax, eax
       jmp      SHORT G_M50849_IG05
						;; size=4 bbWeight=0.50 PerfScore 1.12
G_M50849_IG04:  ;; offset=0008H
       xor      eax, eax
						;; size=2 bbWeight=0.50 PerfScore 0.12
G_M50849_IG05:  ;; offset=000AH
       ret      
						;; size=1 bbWeight=1 PerfScore 1.00

which is effectively equivalent to:

       xor      eax, eax
       ret      

@EgorBo
Copy link
Member Author

EgorBo commented Jun 26, 2023

/azp run runtime-coreclr pgo

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

…tmethodinfo

# Conflicts:
#	src/coreclr/inc/jiteeversionguid.h
@EgorBo EgorBo marked this pull request as ready for review June 30, 2023 08:35
@EgorBo
Copy link
Member Author

EgorBo commented Jun 30, 2023

/azp run runtime-coreclr outerloop, runtime-coreclr jitstress, runtime-extra-platforms, runtime-coreclr pgostress

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@EgorBo
Copy link
Member Author

EgorBo commented Jun 30, 2023

@AndyAyersMS @jakobbotsch PTAL JIT side - it should be ready now, CI failures are not related

@EgorBo
Copy link
Member Author

EgorBo commented Jul 1, 2023

/azp run runtime-coreclr outerloop, runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

}
else if (ctx is InstantiatedType instantiatedCtxType)
{
method = _compilation.TypeSystemContext.GetMethodForInstantiatedType(
Copy link
Member

Choose a reason for hiding this comment

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

This won't work correctly for non-shared generic methods on shared generic types.

For example, G<string>.M<int>. GetTypicalMethodDefinition will drop the method instantiation, so we will end up with G<string>.M<T>. I am not sure whether this problem is reachable in practice currently.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've just pushed a change:

MethodDesc methodTypicalDef = method.GetTypicalMethodDefinition();
if (methodTypicalDef.RequiresInstMethodDescArg())
{
    // Presumably, a rare case: we had MyClass<T1>.Foo<int>() method and
    // GetTypicalMethodDefinition() converted it to MyClass<T1>.Foo<T2>
}
else
{
    method = _compilation.TypeSystemContext.GetMethodForInstantiatedType(methodTypicalDef, instantiatedCtxType);
}

is it enough?

@EgorBo EgorBo force-pushed the pass-context-getmethodinfo branch from 72b2ec5 to 08ac385 Compare July 2, 2023 14:11
@EgorBo
Copy link
Member Author

EgorBo commented Jul 3, 2023

/azp run runtime-coreclr outerloop, runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jkotas
Copy link
Member

jkotas commented Jul 3, 2023

@EgorBo
Copy link
Member Author

EgorBo commented Jul 3, 2023

@EgorBo
Copy link
Member Author

EgorBo commented Jul 3, 2023

@jkotas anything else to be done here?

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 19887f7 into dotnet:main Jul 3, 2023
@EgorBo EgorBo deleted the pass-context-getmethodinfo branch July 3, 2023 21:42
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this pull request Jul 4, 2023
@EgorBo's dotnet#88025 made it possible to undo conservative scanning logic added in dotnet/corert#7618.

Saves 0.4% in size for Stage1 and Stage2 apps.
MichalStrehovsky added a commit that referenced this pull request Jul 4, 2023
@EgorBo's #88025 made it possible to undo conservative scanning logic added in dotnet/corert#7618.

Saves 0.4% in size for Stage1 and Stage2 apps.
@ghost ghost locked as resolved and limited conversation to collaborators Aug 3, 2023
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.

EqualityComparer<string>.Default.Equals is never inlined
6 participants