KEMBAR78
Tier0 allocates on a simple cast (boxing) · Issue #88987 · dotnet/runtime · GitHub
Skip to content

Tier0 allocates on a simple cast (boxing) #88987

@EgorBo

Description

@EgorBo

Minimal repro for https://github.com/dotnet/runtime/pull/88560/files#r1264791578

class Program
{
    static void Main()
    {
        Test(42); // <int> specialization
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Test<T>(T value)
    {
        if (value is IEnumerable enumerable) // always false for <int>
            Consume(enumerable);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Consume(object o) { }
}

Tier1 codegen for Test<int>:

; Assembly listing for method Program:Test[int](int) (FullOpts)
       ret      
; Total bytes of code 1

Tier0 codegen for Test<int>:

; Assembly listing for method Program:Test[int](int) (Tier0)
       push     rbp
       sub      rsp, 48
       lea      rbp, [rsp+30H]
       xor      eax, eax
       mov      qword ptr [rbp-08H], rax
       mov      qword ptr [rbp-10H], rax
       mov      dword ptr [rbp+10H], ecx
       mov      rcx, 0xD1FFAB1E      ; System.Int32
       call     CORINFO_HELP_NEWSFAST ;;;;; <-------- allocation (boxing)
       mov      gword ptr [rbp-10H], rax
       mov      rdx, gword ptr [rbp-10H]
       mov      ecx, dword ptr [rbp+10H]
       mov      dword ptr [rdx+08H], ecx
       mov      rdx, gword ptr [rbp-10H]
       mov      rcx, 0xD1FFAB1E      ; System.Collections.IEnumerable
       call     [CORINFO_HELP_ISINSTANCEOFINTERFACE]
       mov      gword ptr [rbp-08H], rax
       cmp      gword ptr [rbp-08H], 0
       je       SHORT G_M5413_IG03
       mov      rcx, gword ptr [rbp-08H]
       call     [Program:Consume(System.Object)]
G_M5413_IG03:
       nop      
       add      rsp, 48
       pop      rbp
       ret      
; Total bytes of code 100

Metadata

Metadata

Assignees

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