Skip to content

Pass exact context to getMethodInfo - #88025

Merged
jkotas merged 21 commits into
dotnet:mainfrom
EgorBo:pass-context-getmethodinfo
Jul 3, 2023
Merged

Pass exact context to getMethodInfo#88025
jkotas merged 21 commits into
dotnet:mainfrom
EgorBo:pass-context-getmethodinfo

Conversation

@EgorBo

@EgorBoEgorBo commented Jun 25, 2023

Copy link
Copy Markdown
Member

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

Closes#88021

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

New codegen:

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

It is also needed for #87847

@ghostghost assigned EgorBoJun 25, 2023
@ghostghost 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
Copy Markdown

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

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

New codegen:

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

area-CodeGen-coreclr

Milestone:-

@hez2010

Copy link
Copy Markdown
Contributor

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

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

For example:

boolTest()=>newFoo(1,"hello","test")==newFoo(1,"test","hello");recordstructFoo(intx,stringy,stringz);

The codegen for Test is

G_M50849_IG01: ;; offset=0000H ;; size=0 bbWeight=1.00 PerfScore 0.00G_M50849_IG02: ;; offset=0000Hxoreax,eaxje SHORT G_M50849_IG04 ;; size=4 bbWeight=1.00 PerfScore 1.25G_M50849_IG03: ;; offset=0004Hxoreax,eaxjmp SHORT G_M50849_IG05 ;; size=4 bbWeight=0.50 PerfScore 1.12G_M50849_IG04: ;; offset=0008Hxoreax,eax ;; size=2 bbWeight=0.50 PerfScore 0.12G_M50849_IG05: ;; offset=000AHret ;; size=1 bbWeight=1 PerfScore 1.00

which is effectively equivalent to:

xoreax,eaxret

@EgorBo

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-coreclr pgo

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

EgorBo added 2 commits June 28, 2023 23:46
…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
Copy Markdown
MemberAuthor

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

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 4 pipeline(s).

Comment threadsrc/coreclr/jit/importercalls.cpp
@EgorBo

Copy link
Copy Markdown
MemberAuthor

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

@EgorBo

Copy link
Copy Markdown
MemberAuthor

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

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

Comment threadsrc/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
}
else if (ctx is InstantiatedType instantiatedCtxType)
{
method = _compilation.TypeSystemContext.GetMethodForInstantiatedType(

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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:

MethodDescmethodTypicalDef=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
EgorBoforce-pushed the pass-context-getmethodinfo branch from 72b2ec5 to 08ac385CompareJuly 2, 2023 14:11
@EgorBo

Copy link
Copy Markdown
MemberAuthor

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

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@jkotas

Copy link
Copy Markdown
Member

Comment threadsrc/coreclr/tools/Common/JitInterface/CorInfoImpl.cs Outdated
@EgorBo

EgorBo commented Jul 3, 2023

Copy link
Copy Markdown
MemberAuthor

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@EgorBo

Copy link
Copy Markdown
MemberAuthor

@jkotas anything else to be done here?

@jkotasjkotas left a comment

Copy link
Copy Markdown
Member

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:mainJul 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.
@ghostghost locked as resolved and limited conversation to collaborators Aug 3, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclrCLR 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

@EgorBo@hez2010@jkotas@ayende@jakobbotsch@AndyAyersMS