Skip to content

JIT: typeof() is not propagated/folded #71909

Closed
@EgorBo

Description

@EgorBo

From #71685 (comment)

bool Test()
{
    Type t = typeof(int);
    Console.WriteLine();
    return t == typeof(uint);
}

Current codegen:

; Method Program:Test():bool:this
G_M57035_IG01:
       push     rsi
       sub      rsp, 32
G_M57035_IG02:
       mov      rcx, 0xD1FFAB1E      ; System.Int32
       call     CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE
       mov      rsi, rax
       call     [System.Console:WriteLine()]
       mov      rcx, 0xD1FFAB1E      ; System.UInt32
       call     CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE
       cmp      rax, rsi
       sete     al
       movzx    rax, al
G_M57035_IG03:
       add      rsp, 32
       pop      rsi
       ret      
; Total bytes of code: 59

Expected codegen:

; Method Program:Test():bool:this
G_M57035_IG01:
       sub      rsp, 40
G_M57035_IG02:
       call     [System.Console:WriteLine()]
       xor      eax, eax
G_M57035_IG03:
       add      rsp, 40
       ret      
; Total bytes of code: 17

NOTE: it's not about Forward Substitution Phase, a similar pattern in #71685 appears later after Optimize-Layout phase.

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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions