Skip to content

Rely on PGO for isinst/castclass - #65922

Merged
EgorBo merged 9 commits into
dotnet:mainfrom
EgorBo:use-pgo-for-isinst
Apr 1, 2022
Merged

Rely on PGO for isinst/castclass#65922
EgorBo merged 9 commits into
dotnet:mainfrom
EgorBo:use-pgo-for-isinst

Conversation

@EgorBo

@EgorBoEgorBo commented Feb 26, 2022

Copy link
Copy Markdown
Member

Follow up to #65460 (and d-o)

Example (with DOTNET_JitCastProfiling=1):

usingSystem.Runtime.CompilerServices;usingSystem.Threading;publicinterfaceIClass{}publicclassClassA:IClass{}publicclassClassB:ClassA{}publicclassProgram{[MethodImpl(MethodImplOptions.NoInlining)]staticClassACastToClassA(objecto)=>(ClassA)o;// currently we always emit a fast path for ClassA here// but in my case o is always ClassB (PGO helps)[MethodImpl(MethodImplOptions.NoInlining)]staticboolIsClassA(objecto)=>oisClassA;// we don't expand it without PGO[MethodImpl(MethodImplOptions.NoInlining)]staticIClassCastToIClass(objecto)=>(IClass)o;// we don't expand it without PGO[MethodImpl(MethodImplOptions.NoInlining)]staticboolIsIClass(objecto)=>oisIClass;// we don't expand it without PGOpublicstaticvoidMain(){// promote methods to tier1varb=newClassB();for(inti=0;i<100;i++){CastToClassA(b);IsClassA(b);CastToIClass(b);IsIClass(b);Thread.Sleep(16);}}}

Codegen diff: https://www.diffchecker.com/RFblv9RB

@ghostghost assigned EgorBoFeb 26, 2022
@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 26, 2022
@ghost

Copy link
Copy Markdown

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

Issue Details

Follow up to #65460

Example (with DOTNET_JitCastProfiling=1):

usingSystem.Runtime.CompilerServices;usingSystem.Threading;publicinterfaceIClass{}publicclassClassA:IClass{}publicclassClassB:ClassA{}publicclassProgram{[MethodImpl(MethodImplOptions.NoInlining)]staticClassACastToClassA(objecto)=>(ClassA)o;[MethodImpl(MethodImplOptions.NoInlining)]staticboolIsClassA(objecto)=>oisClassA;[MethodImpl(MethodImplOptions.NoInlining)]staticIClassCastToIClass(objecto)=>(IClass)o;[MethodImpl(MethodImplOptions.NoInlining)]staticboolIsIClass(objecto)=>oisIClass;publicstaticvoidMain(){// promote methods to tier1varb=newClassB();for(inti=0;i<100;i++){CastToClassA(b);IsClassA(b);CastToIClass(b);IsIClass(b);Thread.Sleep(16);}}}

Codegen diff: https://www.diffchecker.com/RFblv9RB

Author:EgorBo
Assignees:EgorBo
Labels:

area-CodeGen-coreclr

Milestone:-

Comment threadsrc/coreclr/jit/importer.cpp
@EgorBo
EgorBo marked this pull request as ready for review March 21, 2022 08:28
@EgorBo

EgorBo commented Mar 21, 2022

Copy link
Copy Markdown
MemberAuthor

@AndyAyersMS@jakobbotsch PTAL

This PR consumes profile data from mibc for casts/isinst. I guarded it with DOTNET_JitConsumeProfileForCasts just to wait till dotnet-optimization properly propagates mibc with casts/isinst.

Also, I added "random class" stress mode support for it

@EgorBo

Copy link
Copy Markdown
MemberAuthor

@AndyAyersMS@jakobbotsch PTAL

CORINFO_CLASS_HANDLE likelyCls = likelyClass.clsHandle;

if ((likelyCls != NO_CLASS_HANDLE) &&
(likelyClass.likelihood > (UINT32)JitConfig.JitGuardedDevirtualizationChainLikelihood()))

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.

Should this rather get its own config variable?

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.

Just didn't want to produce even more variables 😄 and the default value for this one was OK to me.
in my other PR to add "multiple guesses" I slightly changed the whole logic so I'll leave it as is for now

@EgorBo
EgorBo merged commit f249a3d into dotnet:mainApr 1, 2022
@ghostghost locked as resolved and limited conversation to collaborators May 2, 2022
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.

3 participants

@EgorBo@jakobbotsch@Wraith2