Uh oh!
There was an error while loading. Please reload this page.
GDV: don't emit fallback call if classes are "exact" - #87055
Conversation
ghost
commented
Jun 2, 2023
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsusingSystem;usingSystem.Runtime.CompilerServices;usingSystem.Threading;publicinterfaceIAnimal{voidMakeSound();}publicclassCat:IAnimal{publicvoidMakeSound()=>Console.WriteLine("Meow!");}publicclassDog:IAnimal{publicvoidMakeSound()=>Console.WriteLine("Woof!");}publicclassCow:IAnimal{publicvoidMakeSound()=>Console.WriteLine("Moo!");}publicclassProgram{publicstaticvoidMain(string[]args){Test(newCat());Test(newDog());Test(newCow());}[MethodImpl(MethodImplOptions.NoInlining)]staticvoidTest(IAnimala)=>a.MakeSound();}NativeAOT codegen for ; Method Program:Test(IAnimal)subrsp,40learax,[(reloc 0x4000000000423000)]cmp qword ptr [rcx],rax ;; is it 'Cat'?jne SHORT G_M31564_IG04learcx, gword ptr [(reloc 0x4000000000423028)] ;; '"Meow!"'call System.Console:WriteLine(System.String)jmp SHORT G_M31564_IG07G_M31564_IG04: ;; offset=001EHlearax,[(reloc 0x4000000000423010)]cmp qword ptr [rcx],rax ;; is it 'Dog'?jne SHORT G_M31564_IG06learcx, gword ptr [(reloc 0x4000000000422f98)] ;; '"Woof!"'call System.Console:WriteLine(System.String)jmp SHORT G_M31564_IG07G_M31564_IG06: ;; offset=0038Hlearcx, gword ptr [(reloc 0x4000000000422f70)] ;; '"Moo!"'call System.Console:WriteLine(System.String)G_M31564_IG07: ;; offset=0044Hnopaddrsp,40ret; Total bytes of code: 74Virtual callback is not emitted since we took care of all possible classes implementing the given interface ("closed world" on NativeAOT). We might still emit it if we e.g. fail to inline one of the candidates (we currently don't do GDV just to devirtualize a call, we only do that when we're able to inline it).
|
EgorBo
commented
Jun 2, 2023
For reference, codegen for JIT: staticvoidMain(){for(inti=0;i<200;i++){Test(newCat());Test(newDog());Test(newCow());Thread.Sleep(16);}}[MethodImpl(MethodImplOptions.NoInlining)]staticvoidTest(IAnimala)=>a.MakeSound();; Assembly listing for method Program:Test(IAnimal)pushrsisubrsp,32movrsi, qword ptr [rcx]movrax,0x7FFF53C41C88 ; Catcmprsi,raxjne SHORT G_M31564_IG04movrcx,0x26780208F80 ; 'Meow!'call[System.Console:WriteLine(System.String)]jmp SHORT G_M31564_IG07G_M31564_IG04:movrax,0x7FFF53C41E48 ; Dogcmprsi,raxjne SHORT G_M31564_IG06movrcx,0x26780209128 ; 'Woof!'call[System.Console:WriteLine(System.String)]jmp SHORT G_M31564_IG07G_M31564_IG06:movrax,0x7FFF53C42008 ; Cowcmprsi,raxjne SHORT G_M31564_IG09movrcx,0x26780209148 ; 'Moo!'call[System.Console:WriteLine(System.String)]G_M31564_IG07:nopaddrsp,32poprsiretG_M31564_IG09:movr11,0x7FFF53130280call[r11]IAnimal:MakeSound():thisjmp SHORT G_M31564_IG07(PGO-driven) |
EgorBo
commented
Jun 2, 2023
/azp run runtime-extra-platforms, runtime-coreclr pgo |
|
Azure Pipelines successfully started running 2 pipeline(s). |
EgorBo
commented
Jun 2, 2023
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
EgorBo
commented
Jun 3, 2023
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
EgorBo
commented
Jun 4, 2023
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
EgorBo
commented
Jun 8, 2023
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
EgorBo
commented
Jun 10, 2023
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
EgorBo
commented
Jun 10, 2023
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
EgorBo
commented
Jun 11, 2023
@AndyAyersMS PTAL, it passes NativeAOT outerloop tests + 3 type checks |
| // Distribute the rounding error and just apply it to the first entry. | ||
| // Assume that there is no error If we have unknown handles. | ||
| if (numberOfClasses == h.m_totalCount) | ||
| if (!containsUnknownHandles) |
There was a problem hiding this comment.
This is an unrelated change, it's just that I used a wrong check in #86965 so it didn't work properly
Contributes to #86769 and closes#86235
NativeAOT codegen for
Test:Virtual callback is not emitted since we took care of all possible classes implementing the given interface ("closed world" on NativeAOT). We might still emit it if we e.g. fail to inline one of the candidates (we currently don't do GDV just to devirtualize a call, we only do that when we're able to inline it) -- we might want to do that for cases where interface calls are expensive but that's a different task in #86769