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

PGO: simple generic method is not inlined #88299

Closed
EgorBo opened this issue Jul 2, 2023 · 2 comments
Closed

PGO: simple generic method is not inlined #88299

EgorBo opened this issue Jul 2, 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 Jul 2, 2023

for (int i = 0; i < 100; i++)
{
    Test(new ObjImpl<string>());
    Thread.Sleep(16);
}

[MethodImpl(MethodImplOptions.NoInlining)]
static object Test(IObj o) => o.GetObj();


public interface IObj
{
    object GetObj();
}

public class ObjImpl<T> : IObj
{
    public object GetObj() => typeof(T);
}

Codegen for Test in Tier1:

; Assembly listing for method Program:<<Main>$>g__Test|0_0(IObj):System.Object (Tier1)
       sub      rsp, 40
       mov      rax, 0xD1FFAB1E  ; ObjImpl`1[System.String]
       cmp      qword ptr [rcx], rax
       jne      SHORT G_M33634_IG06
       call     [ObjImpl`1[System.__Canon]:GetObj():System.Object:this]
G_M33634_IG04:
       nop      
       add      rsp, 40
       ret      
G_M33634_IG06:
       mov      r11, 0xD1FFAB1E      ; code for IObj:GetObj():System.Object:this
       call     [r11]IObj:GetObj():System.Object:this
       jmp      SHORT G_M33634_IG04
; Total bytes of code 46,

GDV is applied but the method is not inlined, presumably, the root cause is the same as in #87597 - generic context from the GDV candidate is not kept (but I am not sure, decided to file since I noticed a similiar pattern in real code)

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 2, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 2, 2023
@ghost
Copy link

ghost commented Jul 2, 2023

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

Issue Details
for (int i = 0; i < 100; i++)
{
    Test(new ObjImpl<string>());
    Thread.Sleep(16);
}

[MethodImpl(MethodImplOptions.NoInlining)]
static object Test(IObj o) => o.GetObj();


public interface IObj
{
    object GetObj();
}

public class ObjImpl<T> : IObj
{
    public object GetObj() => typeof(T);
}

Codegen for Test in Tier1:

; Assembly listing for method Program:<<Main>$>g__Test|0_0(IObj):System.Object (Tier1)
       sub      rsp, 40
       mov      rax, 0xD1FFAB1E  ; ObjImpl`1[System.String]
       cmp      qword ptr [rcx], rax
       jne      SHORT G_M33634_IG06
       call     [ObjImpl`1[System.__Canon]:GetObj():System.Object:this]
G_M33634_IG04:
       nop      
       add      rsp, 40
       ret      
G_M33634_IG06:
       mov      r11, 0xD1FFAB1E      ; code for IObj:GetObj():System.Object:this
       call     [r11]IObj:GetObj():System.Object:this
       jmp      SHORT G_M33634_IG04
; Total bytes of code 46,

GDV is applied but the method is not inlined, presumably, the root cause is the same as in #87597 - generic context from the GDV candidate is not kept.

Author: EgorBo
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo EgorBo added this to the 8.0.0 milestone Jul 2, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jul 2, 2023
@EgorBo EgorBo self-assigned this Jul 2, 2023
@EgorBo
Copy link
Member Author

EgorBo commented Jul 22, 2023

Just checked, this issue will be closed by #87847
codegen diff (Main vs that PR): https://www.diffchecker.com/iyxpsemY/ (method is inlined now)
cc @davidwrighton @AndyAyersMS

@EgorBo EgorBo closed this as completed Jul 26, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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

1 participant