Skip to content

Remove unnecessary pinning over non-unloadable RVA fields #118802

@EgorBo

Description

@EgorBo
    unsafe void Test()
    {
        ReadOnlySpan<byte> utfStr = "hello"u8;
        fixed (byte* ptr = utfStr)
        {
            Console.WriteLine((nint)ptr);
        }
    }

Actual codegen (in an non-unloadable assembly):

; Method Test_DevDiv_255294:Test():this (FullOpts)
       sub      rsp, 40
       mov      rcx, 0x16992A529E8      ; static handle
       mov      bword ptr [rsp+0x20], rcx
       mov      rcx, 0x16992A529E8
       call     [System.Console:WriteLine(long)]
       xor      eax, eax
       mov      bword ptr [rsp+0x20], rax
       add      rsp, 40
       ret      
; Total bytes of code: 47

Expected codegen:

; Method Test_DevDiv_255294:Test():this (FullOpts)
       sub      rsp, 40
       mov      rcx, 0x29658B929E8
       call     [System.Console:WriteLine(long)]
       nop
       add      rsp, 40
       ret      

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