Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDV: Multiple type-checks work items #86769

Open
9 of 14 tasks
EgorBo opened this issue May 25, 2023 · 2 comments
Open
9 of 14 tasks

GDV: Multiple type-checks work items #86769

EgorBo opened this issue May 25, 2023 · 2 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@EgorBo
Copy link
Member

EgorBo commented May 25, 2023

A tracking issue for progress related to GDV with multiple type-checks. Essentially, today we expand virtual calls like this:

obj.DoWork(); // interface or virtual call and JIT doesn't know obj's exact type

Jit is able to record (probe) obj's type in Tier0 so then in Tier1 we can expand it like this;

if (obj is Class1)
    ((Class1)obj).DoWork(); // no longer virtual, can be inlined
else
    obj.DoWork(); // virtual call as a fallback

We call this Guarded Devirtualization or GDV.
However, for polymorphic virtual call-sites where we see more than a single dominating class we want to be able to expand multiple candidates, e.g.:

if (obj is Class1)
    ((Class1)obj).DoWork();
if (obj is Class2)
    ((Class2)obj).DoWork();
if (obj is Class3 || obj is Class4) // e.g. they share the same method since DoWork is not overriden in Class4
    ((Class3)obj).DoWork();
else
    obj.DoWork(); // fallback (can be omitted in case of NativeAOT)

Tasks:

@ghost ghost added the untriaged New issue has not been triaged by the area owner label May 25, 2023
@ghost
Copy link

ghost commented May 25, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

A tracking issue for progress related to GDV with multiple type-checks. Essentially, today we expand virtual calls like this:

obj.DoWork();

is profiled and is expanded like this in Tier1:

if (obj is Class1)
    ((Class1)obj).DoWork(); // no longer virtual, can be inlined
else
    obj.DoWork(); // fallback

However, for virtual call-sites where we see more than a single dominating class we want to be able to expand multiple candidates, e.g.:

if (obj is Class1)
    ((Class1)obj).DoWork();
if (obj is Class2)
    ((Class2)obj).DoWork();
if (obj is Class3 || obj is Class4) // e.g. they share the same method
    ((Class3)obj).DoWork();
else
    obj.DoWork(); // fallback (can be omitted in case of NativeAOT)

Tasks:

  • Basic prototype (WIP: Guarded devirtualization: multiple type checks #86551) for NativeAOT
  • Enable the basic prototype for Dynamic PGO
  • Omit the virtual fallback in case of NativeAOT when we know all possible targets Guarded devirtualization based on whole program view #86235
  • Merge type checks if they target the same method
  • Currently we only do GDV when candidates will be inlined, we should consider doing that for non-profitable-to-inline interface calls to (at least for NativeAOT) if it's beneficial
  • Currently we give up on all candidates if some of them are not inlineable - we should either ignore them or just devirtualize like mentioned above ^
  • Calculate optimal number of type checks (depending on their likelihoods)
Author: EgorBo
Assignees: -
Labels:

untriaged, area-NativeAOT-coreclr

Milestone: -

@EgorBo EgorBo added this to the Future milestone May 25, 2023
@EgorBo EgorBo removed the untriaged New issue has not been triaged by the area owner label May 25, 2023
@EgorBo EgorBo self-assigned this May 25, 2023
@teo-tsirpanis teo-tsirpanis added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI and removed area-NativeAOT-coreclr labels May 25, 2023
@ghost
Copy link

ghost commented May 25, 2023

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

Issue Details

A tracking issue for progress related to GDV with multiple type-checks. Essentially, today we expand virtual calls like this:

obj.DoWork(); // interface or virtual call and JIT doesn't know obj's exact type

Jit is able to record (probe) obj's type in Tier0 so then in Tier1 we can expand it like this;

if (obj is Class1)
    ((Class1)obj).DoWork(); // no longer virtual, can be inlined
else
    obj.DoWork(); // virtual call as a fallback

We call this Guarded Devirtualization or GDV.
However, for polymorphic virtual call-sites where we see more than a single dominating class we want to be able to expand multiple candidates, e.g.:

if (obj is Class1)
    ((Class1)obj).DoWork();
if (obj is Class2)
    ((Class2)obj).DoWork();
if (obj is Class3 || obj is Class4) // e.g. they share the same method since DoWork is not overriden in Class4
    ((Class3)obj).DoWork();
else
    obj.DoWork(); // fallback (can be omitted in case of NativeAOT)

Tasks:

  • Basic prototype (WIP: Guarded devirtualization: multiple type checks #86551) for NativeAOT
  • Enable the basic prototype for Dynamic PGO
  • Omit the virtual fallback in case of NativeAOT when we know all possible targets Guarded devirtualization based on whole program view #86235
  • Merge type checks if they target the same method - if (obj is Class3 || obj is Class4)
  • Currently we only do GDV when candidates will be inlined, we should consider doing that for non-profitable-to-inline interface calls to (at least for NativeAOT) if it's beneficial
  • Currently we give up on all candidates if some of them are not inlineable - we should either ignore them or just devirtualize like mentioned above ^
  • Calculate optimal number of type checks (depending on their likelihoods)
  • Implement GDV chaining for cases when we have more than 1 candidate (GDV chaining is a feature where two subsequent virtual calls on top of the same object can share the type-check)
Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: Future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

No branches or pull requests

2 participants