Uh oh!
There was an error while loading. Please reload this page.
Guarded devirtualization: multiple type checks - #86551
Conversation
ghost
commented
May 21, 2023
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsThis PR builds a basic infrastructure to enable multiple GDV checks (for all runtimes), but for now it's only enabled for NativeAOT where for daul-morphic interface calls we can devirtualize fallback too, e.g.: publicinterfaceIValue{intGetValue();}publicclassMyClass1:IValue{publicintGetValue()=>10;}publicclassMyClass2:IValue{publicintGetValue()=>100;}staticintTest(IValueval)=>val.GetValue();Old NativeAOT codegen for ; Assembly listing for method Program:Test(IValue):intsubrsp,40lear10,[(reloc 0x4000000000420060)]call[r10]IValue:GetValue():int:this ;; interface call, not devirtualizednopaddrsp,40ret; Total bytes of code 20New codegen: ; Assembly listing for method Program:Test(IValue):intlearax,[(reloc 0x4000000000420fe0)]movedx,100movr8d,10cmp qword ptr [rcx],raxmoveax,r8d cmovne eax,edxret; Total bytes of code 28(cmove for 10 or 100 based on type check for Should not be difficult to enable for JIT and multiple type checks (but will need some work around chaining)
|
MichalStrehovsky
commented
May 22, 2023
Out of curiosity - what will be the interaction between this and PGO data? If PGO says the likely class is X and whole program analysis says the possibilities are X and Y. Would we trust PGO or the overapproximation from whole program analysis? It's possible this question doesn't make much difference for 2 cases, but if we have PGO say X and whole program analysis say X, Y, Z, U, V, W, maybe we can trust PGO. |
EgorBo
commented
May 22, 2023
I think we can consult with PGO here yes, but, presumably, it's a rare case for AOT now because Static PGO is quite complicated to setup and the process is not documented (and tested) well. |
EgorBo
commented
May 22, 2023
/azp list |
This comment was marked as resolved.
This comment was marked as resolved.
EgorBo
commented
May 22, 2023
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
MichalStrehovsky
commented
May 22, 2023
We have PGO data that we ship with the product - one of the things it's trained on is ASP.NET. So this could be relevant for ASP.NET scenarios and doesn't require the complicated setup there because it comes with the compiler. |
I plan to work on this in iterations when I have time so definitely something I'll consider. For now I changed the logic to rely on PGO if it exists, otherwise - go the exact classes list. Also, I completely rewrote the PR so now it has a full-fledged multiple-candidates support (controlled via |
EgorBo
commented
May 23, 2023
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| assert(elseLikelihood <= 100); | ||
| elseBlock->setBBProfileWeight(newWeight); | ||
| elseBlock->inheritWeightPercentage(currBlock, elseLikelihood); |
There was a problem hiding this comment.
For the multi-guess exact case this likelihood should end up at zero, right? We think we know all the possibilities.
There was a problem hiding this comment.
Yes, but the logic is shared with non-exact case where fallback may have non-zero likelihood (Dynamic PGO)
I plan to enable "no fallback needed" separately, I am thinking of doing something like "we're importing the last type-check and the call has GTF_M_EXACT_GDV flag --> convert the last pair of check-then to elseBock.
EgorBo
commented
May 25, 2023
Thanks! I still plan to address some of your comments as part of this PR so will ping you again once I'm done🙂 Meanwhile, I filed #86769 to record the ideas |
EgorBo
commented
May 26, 2023
/azp run runtime-extra-platforms, runtime-coreclr pgo, runtime-coreclr pgostress |
|
Azure Pipelines successfully started running 3 pipeline(s). |
@AndyAyersMS I've addressed your feedback - |
AndyAyersMS
left a comment
There was a problem hiding this comment.
Still LGTM.
IIRC 3 is a common value for the number of checks in these sorts of things, once you get past that then (assuming you are testing candidates in decreasing order of likelihood) the cost of that many (possibly mis-predicted) branches starts to overwhelm the benefit.
EgorBo
commented
May 26, 2023
jakobbotsch
commented
May 30, 2023
The MinOpts TP impact of this change seems quite significant, is it expected? Also lots of misses, so hard to know how accurate those diffs are, is it possible to recollect the diffs on the new collection now? |
kunalspathak
commented
May 30, 2023
Agree. Just noticed at the TP numbers. |
EgorBo
commented
May 31, 2023
Yes, because I call a new JIT-EE API for each virtual call ( The 0.2% MinOpts regression comes from unexpected calls to |
EgorBo
commented
May 31, 2023
Mitigated via #86949 |
Contributes to #86769 and #86235
This PR builds a basic infrastructure to enable multiple GDV checks (for all runtimes), but for now it's only enabled for NativeAOT:
Demo:
NativeAOT codegen for
Test(without static pgo):