KEMBAR78
JIT: Don't give up on runtime lookup in inliner too early · Issue #81432 · dotnet/runtime · GitHub
Skip to content

JIT: Don't give up on runtime lookup in inliner too early #81432

@EgorBo

Description

@EgorBo
static bool Test<T>() => Callee<T>();

static bool Callee<T>() => typeof(T) == typeof(int);

It is expected that Test<string> will be compiled to just return false. Instead, it's compiled down to:

; Assembly listing for method Program:<<Main>$>g__Test|0_0[System.__Canon]():bool
G_M24604_IG01:
       sub      rsp, 40
       mov      qword ptr [rsp+20H], rcx
G_M24604_IG02:
       mov      rdx, qword ptr [rcx+38H]
       mov      rdx, qword ptr [rdx+10H]
       test     rdx, rdx
       je       SHORT G_M24604_IG04
G_M24604_IG03:
       jmp      SHORT G_M24604_IG05
G_M24604_IG04:
       mov      rdx, 0xD1FFAB1E      ; global ptr
       call     CORINFO_HELP_RUNTIMEHANDLE_METHOD
       mov      rdx, rax
G_M24604_IG05:
       mov      rcx, rdx
       call     [Program:<<Main>$>g__Callee|0_1[System.__Canon]():bool]
       nop      
G_M24604_IG06:
       add      rsp, 40
       ret      
; Total bytes of code 57

It seems that JIT's inliner could be a bit smarter here when currently it gives up when it sees ldtoken T! as a potential runtime lookup. We either can teach it to recognize typeof() == typeof() idiom upfront (and fold) or we can do a sort of "I've just hit a runtime lookup, let me import up to 3 more opcodes to see if I will be able to fold it"
cc @AndyAyersMS @jkotas

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions