Skip to content

Runtime lookup clean up, enable for helper-based tail calls - #83430

Merged
EgorBo merged 4 commits into
dotnet:mainfrom
EgorBo:followup-runtimelookup
Mar 17, 2023
Merged

Runtime lookup clean up, enable for helper-based tail calls#83430
EgorBo merged 4 commits into
dotnet:mainfrom
EgorBo:followup-runtimelookup

Conversation

@EgorBo

@EgorBoEgorBo commented Mar 15, 2023

Copy link
Copy Markdown
Member

Follow up to #81635

Clean up some dead code and enable runtime lookup expansion for helper-based tail-calls where we previously only used slow fallbacks.

@ghostghost assigned EgorBoMar 15, 2023
@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 15, 2023
@ghost

Copy link
Copy Markdown

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

Issue Details

Clean up some dead code and enable runtime lookup expansion for helper-based tail-calls where we previously only used slow fallbacks.

Author:EgorBo
Assignees:EgorBo
Labels:

area-CodeGen-coreclr

Milestone:-

Comment threadsrc/coreclr/jit/importer.cpp Outdated
impAppendTree(qmark, CHECK_SPILL_NONE, impCurStmtDI);

return gtNewLclvNode(slotLclNum, TYP_I_IMPL);
assert(!pRuntimeLookup->testForFixup);

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 should be deleted from JIT/EE interface.

@EgorBo

EgorBo commented Mar 15, 2023

Copy link
Copy Markdown
MemberAuthor

A couple of diffs in coreclr_tests where we have tail. callvirt and didn't use expansion previosly, e.g:

; Program:GenInterfaceForwardG
@@ -39,11 +42,26 @@ G_M7779_IG01: ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref,
mov rsi, r9
; gcrRegs +[rsi]
;; size=44 bbWeight=1 PerfScore 10.58
-G_M7779_IG02: ; bbWeight=1, gcrefRegs=00C0 {rsi rdi}, byrefRegs=0000 {}, byref+G_M7779_IG02: ; bbWeight=1, gcrefRegs=00C0 {rsi rdi}, byrefRegs=0000 {}, byref, isz+ mov rdx, qword ptr [rcx+38H]+ cmp qword ptr [rdx+10H], 32+ jle SHORT G_M7779_IG05+ ;; size=11 bbWeight=1 PerfScore 6.00+G_M7779_IG03: ; bbWeight=0.80, gcrefRegs=00C0 {rsi rdi}, byrefRegs=0000 {}, byref, isz+ mov rdx, qword ptr [rdx+20H]+ test rdx, rdx+ je SHORT G_M7779_IG05+ ;; size=9 bbWeight=0.80 PerfScore 2.60+G_M7779_IG04: ; bbWeight=0.64, gcrefRegs=00C0 {rsi rdi}, byrefRegs=0000 {}, byref, isz+ jmp SHORT G_M7779_IG06+ ;; size=2 bbWeight=0.64 PerfScore 1.28+G_M7779_IG05: ; bbWeight=0.36, gcrefRegs=00C0 {rsi rdi}, byrefRegs=0000 {}, byref
mov rdx, 0xD1FFAB1E ; global ptr
call CORINFO_HELP_RUNTIMEHANDLE_METHOD
; gcr arg pop 0
mov rdx, rax
+ ;; size=18 bbWeight=0.36 PerfScore 0.54+G_M7779_IG06: ; bbWeight=1, gcrefRegs=00C0 {rsi rdi}, byrefRegs=0000 {}, byref
mov rcx, rsi
; gcrRegs +[rcx]
mov r8, 0xD1FFAB1E ; token handle
@@ -67,8 +85,8 @@ G_M7779_IG02: ; bbWeight=1, gcrefRegs=00C0 {rsi rdi}, byrefRegs=0000 {},
; gcr arg pop 0
mov rax, gword ptr [rsp+30H]
; gcrRegs +[rax]
- ;; size=91 bbWeight=1 PerfScore 11.50-G_M7779_IG03: ; bbWeight=1, epilog, nogc, extend+ ;; size=73 bbWeight=1 PerfScore 10.00+G_M7779_IG07: ; bbWeight=1, epilog, nogc, extend
add rsp, 96
pop rbx
pop rsi
@@ -76,7 +94,7 @@ G_M7779_IG03: ; bbWeight=1, epilog, nogc, extend
ret ;; size=8 bbWeight=1 PerfScore 2.75
-; Total bytes of code 143

@jakobbotsch

Copy link
Copy Markdown
Member

Nice! Any benchmarks?

BTW, doesn't the block layout look kind of odd here:

+G_M7779_IG03: ; bbWeight=0.80, gcrefRegs=00C0 {rsi rdi}, byrefRegs=0000 {}, byref, isz+ mov rdx, qword ptr [rdx+20H]+ test rdx, rdx+ je SHORT G_M7779_IG05+ ;; size=9 bbWeight=0.80 PerfScore 2.60+G_M7779_IG04: ; bbWeight=0.64, gcrefRegs=00C0 {rsi rdi}, byrefRegs=0000 {}, byref, isz+ jmp SHORT G_M7779_IG06+ ;; size=2 bbWeight=0.64 PerfScore 1.28+G_M7779_IG05: ; bbWeight=0.36, gcrefRegs=00C0 {rsi rdi}, byrefRegs=0000 {}, byref
mov rdx, 0xD1FFAB1E ; global ptr
call CORINFO_HELP_RUNTIMEHANDLE_METHOD
; gcr arg pop 0
mov rdx, rax
+ ;; size=18 bbWeight=0.36 PerfScore 0.54+G_M7779_IG06: ; bbWeight=1, gcrefRegs=00C0 {rsi rdi}, byrefRegs=0000 {}, byref

Couldn't this be jne G_M7779_IG06 directly from the hot block instead?

@jakobbotsch

Copy link
Copy Markdown
Member

Quick benchmark:

publicstructForceHelper{publicintA,B,C,D,E,F,G;}publicinterfaceIFoo<T>{longCount(intcount,longsum,ForceHelperfh);}publicunsafeclassC<T>:IFoo<T>{publiclongCount(intiterations,longsum,ForceHelperfh){if(iterations==0)returnsum;ForceHelperlocal=fh;local.A=30;IL.Push(this);IL.Push(iterations-1);IL.Push(sum+iterations);IL.Push(local);IL.Emit.Tail();IL.Emit.Callvirt(newMethodRef(typeof(IFoo<T>),"Count"));returnIL.Return<long>();}}
MethodJobToolchainiterationsMeanErrorStdDevRatio
CountDefaultJob.NET 71000000205.30 ms2.596 ms2.428 ms1.00
CountJob-CEFCSMpr100000047.73 ms0.306 ms0.271 ms0.23

🚀

@EgorBo
EgorBo marked this pull request as ready for review March 15, 2023 10:56
@EgorBo

Copy link
Copy Markdown
MemberAuthor

Quick benchmark:

Thanks for checking - I was puzzled on how to properly benchmark it 🙂.

Couldn't this be jne G_M7779_IG06 directly from the hot block instead?

We emit block layout like this:

// prevBb(BBJ_NONE): [weight: 1.0]// ...//// nullcheckBb(BBJ_COND): [weight: 1.0]// if (*fastPathValue == null)// goto fallbackBb;//// fastPathBb(BBJ_ALWAYS): [weight: 0.8]// rtLookupLcl = *fastPathValue;// goto block;//// fallbackBb(BBJ_NONE): [weight: 0.2]// rtLookupLcl = HelperCall();//// block(...): [weight: 1.0]// use(rtLookupLcl);

We probably need to re-order fastPathBb and fallbackBb

Comment threadsrc/coreclr/vm/prestub.cpp
@EgorBo
EgorBo merged commit 3c38189 into dotnet:mainMar 17, 2023
@EgorBo
EgorBo deleted the followup-runtimelookup branch March 17, 2023 13:31
@ghostghost locked as resolved and limited conversation to collaborators Apr 16, 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.

4 participants

@EgorBo@jakobbotsch@jkotas@AndyAyersMS