Skip to content

calli target fail to inline #13674

@nxtn

Description

@nxtn

The callers can be inline after dotnet/coreclr#13756, but the callees can't.

.assembly extern legacy library mscorlib {}

.assembly legacy library calli_inline {}
.class private auto ansi beforefieldinit calli_test
       extends [mscorlib]System.Object
{
  .field private static int32 a
  .method public static int32 f1() aggressiveinlining aggressiveoptimization
  {
    ldsfld int32 calli_test::a
    ret
  }
  .method public static int32 g1() aggressiveinlining aggressiveoptimization
  {
    ldftn int32 calli_test::f1()
    calli int32 ()
    ret
  }
  .method public hidebysig static int32 Main() cil managed aggressiveoptimization
  {
    .entrypoint
    .maxstack  2
    call int32 calli_test::g1()
    call string [mscorlib]System.Console::ReadLine()
    pop
    ret
  }
}

Actual:

push    rsi
sub     rsp,20h

mov     rax,offset calli_test.f1()
call    rax
mov     esi,eax
call    System.Console.ReadLine()
mov     eax,esi

add     rsp,20h
pop     rsi
ret

Expected:

push    rsi
sub     rsp,20h

mov     esi,[]
call    System.Console.ReadLine()
mov     eax,esi

add     rsp,20h
pop     rsi
ret

However, when I printed the stack trace from inside the callee, it doesn't show up. Earlier I was using stack trace to determine if a method is inline.

  .method public static int32 f1() aggressiveinlining aggressiveoptimization
  {
    newobj instance void [mscorlib]System.Diagnostics.StackTrace::.ctor()
    callvirt instance string [mscorlib]System.Object::ToString()
    call void [mscorlib]System.Console::WriteLine(string)
    ldsfld int32 calli_test::a
    ret
  }
   at calli_test.Main()

(I couldn't figure out how to use jit-dasm in jitutils, it just gave tons of errors!)

category:cq
theme:inlining
skill-level:intermediate
cost:medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions