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

Delegates are not being inlined #56708

Closed
hez2010 opened this issue Aug 2, 2021 · 3 comments
Closed

Delegates are not being inlined #56708

hez2010 opened this issue Aug 2, 2021 · 3 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI tenet-performance Performance related issue

Comments

@hez2010
Copy link
Contributor

hez2010 commented Aug 2, 2021

Description

Repro:

[MethodImpl(MethodImplOptions.NoInlining)]
static int M()
{
    var x = F(5);
    return x();
}

static Func<int> F(int x)
{
    return () => 5 + x;
}

JIT dump for M (Tier1):

push    rbp
mov     rbp,rsp
mov     edi,5
call    <Program>$.<<Main>$>g__F|0_1(Int32)
mov     rsi,rax
mov     rdi,offset methodtable(System.Func`1[[System.Int32, System.Private.CoreLib]])
call    CORINFO_HELP_CHKCASTARRAY
mov     rdi,[rax+8]
call    qword ptr [rax+18h]
nop
pop     rbp
ret

If I have AggressiveInlining on F:

push    rbp
push    r14
push    rbx
lea     rbp,[rsp+10h]
mov     rdi,offset methodtable(<Program>$+<>c__DisplayClass0_0)
call    CORINFO_HELP_NEWSFAST
mov     rbx,rax
mov     dword ptr [rbx+8],5
mov     rdi,offset methodtable(System.Func`1[[System.Int32, System.Private.CoreLib]])
call    CORINFO_HELP_NEWSFAST
mov     r14,rax
lea     rdi,[r14+8]
mov     rsi,rbx
call    CORINFO_HELP_ASSIGN_REF
mov     rdi,offset <Program>$+<>c__DisplayClass0_0.<<Main>$>b__13()
mov     [r14+18h],rdi
mov     rdi,[r14+8]
call    qword ptr [r14+18h]
nop
pop     rbx
pop     r14
pop     rbp
ret

Also, I tried creating the delegate without using lambdas:

[MethodImpl(MethodImplOptions.NoInlining)]
static int M()
{
    var x = Foo(5);
    return x();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static Func<int> Foo(int x)
{
    var d = new D();
    d.x = x;
    return new Func<int>(d.f);
}

sealed class D
{
    public int x;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int f() => 5 + x;
}

It gives codegen:

push    rbp
push    r14
push    rbx
lea     rbp,[rsp+10h]
mov     rdi,offset methodtable(D)
call    CORINFO_HELP_NEWSFAST
mov     rbx,rax
mov     dword ptr [rbx+8],5
mov     rdi,offset methodtable(System.Func`1[[System.Int32, System.Private.CoreLib]])
call    CORINFO_HELP_NEWSFAST
mov     r14,rax
lea     rdi,[r14+8]
mov     rsi,rbx
call    CORINFO_HELP_ASSIGN_REF
mov     rdi,offset D.f()
mov     [r14+18h],rdi
mov     rdi,[r14+8]
call    qword ptr [r14+18h]
nop
pop     rbx
pop     r14
pop     rbp
ret

Expected codegen:

mov     eax, 0xa
ret

Configuration

.NET: 6.0.100-rc.1.21379.19

@hez2010 hez2010 added the tenet-performance Performance related issue label Aug 2, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner labels Aug 2, 2021
@davidfowl
Copy link
Member

Delegates are never inlined #44610

@JulieLeeMSFT JulieLeeMSFT removed the untriaged New issue has not been triaged by the area owner label Aug 2, 2021
@JulieLeeMSFT
Copy link
Member

@hez2010 Is it ok to close this issue because it is answered by davidfowl?

@hez2010
Copy link
Contributor Author

hez2010 commented Aug 2, 2021

@hez2010 Is it ok to close this issue because it is answered by davidfowl?

Sure. I'm closing this issue.

@hez2010 hez2010 closed this as completed Aug 2, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 1, 2021
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 tenet-performance Performance related issue
Projects
None yet
Development

No branches or pull requests

4 participants