Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Aug 1, 2025

Just a small CQ issue I noticed while was checking codegen in #118288

object A;
object B;
object C;
object D;

[MethodImpl(MethodImplOptions.NoInlining)]
private void Test()
{
    object[] roots = new object[] {
        A,B,C,D
    };

    foreach (object key in roots)
        Console.WriteLine(key);
}

Was:

; Method Program:Test():this (FullOpts)
       push     rsi
       push     rbx
       sub      rsp, 88
       xor      eax, eax
       mov      qword ptr [rsp+0x28], rax
       vxorps   xmm4, xmm4, xmm4
       vmovdqu  ymmword ptr [rsp+0x30], ymm4
       mov      qword ptr [rsp+0x50], rax
       mov      rbx, rcx
       mov      rcx, 0x7FFA4D76E6F8      ; System.Object[]
       mov      qword ptr [rsp+0x28], rcx
       lea      rcx, [rsp+0x28]
       mov      dword ptr [rcx+0x08], 4
       lea      rsi, [rsp+0x28]
       mov      rdx, gword ptr [rbx+0x08]
       lea      rcx, [rsi+0x10]
       call     CORINFO_HELP_CHECKED_ASSIGN_REF
       mov      rdx, gword ptr [rbx+0x10]
       lea      rcx, [rsi+0x18]
       call     CORINFO_HELP_CHECKED_ASSIGN_REF
       mov      rdx, gword ptr [rbx+0x18]
       lea      rcx, [rsi+0x20]
       call     CORINFO_HELP_CHECKED_ASSIGN_REF
       mov      rdx, gword ptr [rbx+0x20]
       lea      rcx, [rsi+0x28]
       call     CORINFO_HELP_CHECKED_ASSIGN_REF
       add      rsi, 16
       mov      ebx, 4
G_M36831_IG03:
       mov      rcx, gword ptr [rsi]
       call     [System.Console:WriteLine(System.Object)]
       add      rsi, 8
       dec      ebx
       jne      SHORT G_M36831_IG03
       add      rsp, 88
       pop      rbx
       pop      rsi
       ret      
; Total bytes of code: 148

Now:

; Method Program:Test():this (FullOpts)
       push     rsi
       push     rbx
       sub      rsp, 88
       xor      eax, eax
       mov      qword ptr [rsp+0x28], rax
       vxorps   xmm4, xmm4, xmm4
       vmovdqu  ymmword ptr [rsp+0x30], ymm4
       mov      qword ptr [rsp+0x50], rax
       mov      rax, 0x7FFA4B2CE6F8      ; System.Object[]
       mov      qword ptr [rsp+0x28], rax
       lea      rax, [rsp+0x28]
       mov      dword ptr [rax+0x08], 4
       lea      rbx, [rsp+0x28]
       mov      rax, gword ptr [rcx+0x08]
       mov      gword ptr [rbx+0x10], rax
       mov      rax, gword ptr [rcx+0x10]
       mov      gword ptr [rbx+0x18], rax
       mov      rax, gword ptr [rcx+0x18]
       mov      gword ptr [rbx+0x20], rax
       mov      rcx, gword ptr [rcx+0x20]
       mov      gword ptr [rbx+0x28], rcx
       add      rbx, 16
       mov      esi, 4
G_M36831_IG03:  ;; offset=0x0065
       mov      rcx, gword ptr [rbx]
       call     [System.Console:WriteLine(System.Object)]
       add      rbx, 8
       dec      esi
       jne      SHORT G_M36831_IG03
       add      rsp, 88
       pop      rbx
       pop      rsi
       ret      
; Total bytes of code: 125

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 1, 2025
@EgorBo EgorBo added this to the 11.0.0 milestone Aug 1, 2025
@EgorBo
Copy link
Member Author

EgorBo commented Aug 6, 2025

I'll leave this for .NET 11.0

There is a fragile assumption that whatever IND source got the VNF_JitNewLclArr Value Number must be converted to an actual stack allocation (so the fgExpandStackArrayAllocations phase must kick in and handle all of them) cc @AndyAyersMS

@dotnet-policy-service dotnet-policy-service bot removed this from the 11.0.0 milestone Sep 6, 2025
@dotnet-policy-service
Copy link
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant