Skip to content

[Wasm RyuJit] codegen for small structs #125199

Closed

Description

@AndyAyersMS
N006 (???,???) [000027] -----+-----                   t27 =    CNS_INT   int    0
                                                            /--*  t6     int    arg3 $3
                                                            +--*  t9     int    gctx $2
                                                            +--*  t26    int    wasm sp $0
                                                            +--*  t25    int    r2r cell $1
                                                            +--*  t27    int    wasm pep $4
N007 (???,???) [000007] --CXG+-----                    t7 = *  CALL r2r_ind int    System.Runtime.CompilerServices.ObjectHandleOnStack:Create[System.__Canon](byref):System.Runtime.CompilerServices.ObjectHandleOnStack
                                                            /--*  t7     int
N008 (???,???) [000016] DACXG+-----                         *  STORE_LCL_VAR struct<System.Runtime.CompilerServices.ObjectHandleOnStack, 4> V10 tmp3

This blows up under RewriteLocalStackStore because of the int/struct mix.

To repro, try crossgenning a wasm SPC with rsp file like the following:

--targetos:browser
--targetarch:wasm
--obj-format=wasm
--codegenopt:JitDump=Ctor
--singlemethodtypename:"System.Array" 
--singlemethodname:"Ctor" 
--singlemethodindex:2
-r:"c:\repos\runtime2\artifacts\tests\coreclr\browser.wasm.Debug\Tests\Core_Root\*.dll"
"c:\repos\runtime2\artifacts\tests\coreclr\browser.wasm.Debug\Tests\Core_Root\System.Private.CoreLib.dll"

Activity

  1. added
    untriaged
    on Mar 5, 2026
  2. added
    area-CodeGen-coreclr
    on Mar 5, 2026
  3. dotnet-policy-service commented on Mar 5, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  4. AndyAyersMS commented on Mar 5, 2026

    @AndyAyersMS
    MemberAuthor

    Also an assert in LowerStoreLocCommon

    lowering store lcl var/field (before):
    N001 (???,???) [000013] -----+-----                   t13 =    LCL_VAR   int    V00 SP
    N002 (???,???) [000000] -----+-----                    t0 =    LCL_VAR   byref  V01 this
    N003 (???,???) [000012] H----+-----                   t12 =    CNS_INT(h) int    0x420068 ftn
    N004 (???,???) [000014] -----+-----                   t14 =    CNS_INT   int    0
                                                                /--*  t13    int    wasm sp $0
                                                                +--*  t0     byref  this $1
                                                                +--*  t12    int    r2r cell $2
                                                                +--*  t14    int    wasm pep $3
    N005 (???,???) [000001] --CXG+-----                    t1 = *  CALL r2r_ind long   System.Environment+ProcessCpuUsage:get_UserTime():System.TimeSpan:this
                                                                /--*  t1     long
    N006 (???,???) [000002] DACXG+-----                         *  STORE_LCL_VAR struct<System.TimeSpan, 8> V03 loc1
    
    Assertion failed 'call->HasMultiRegRetVal()' in 'System.Environment+ProcessCpuUsage:get_TotalTime():System.TimeSpan:this' during 'Lowering nodeinfo' (IL size 18; hash 0xf54dffa9; MinOpts)
    

    Here layout->GetSlotCount() is returning 2 instead of 1 for Wasm and pushing us down the multi-reg return path, since it is dividing the return type size (8) by pointer size (4).

    But the logic in LowerStoreLocCommon here is convoluted and needs further reviewing.

    To repro modify the above RSP to have

    --singlemethodtypename:"System.Environment+ProcessCpuUsage" 
    --singlemethodname:"get_TotalTime" 
    --singlemethodindex:1
    
  5. AndyAyersMS commented on Mar 5, 2026

    @AndyAyersMS
    MemberAuthor

    For

    --singlemethodtypename:"System.BitConverter" 
    --singlemethodname:"GetBytes" 
    --singlemethodindex:11
    

    we hit

    Assertion failed 'segment.Offset + segment.Size <= lvaLclExactSize(lclNum)' in 'System.BitConverter:GetBytes(System.Numerics.BFloat16):byte[]' during 'Pre-import' (IL size 44; hash 0xe1f7a5db; Optimization-Level-Not-Yet-Set)
    

    (very early before we have IR)

    This is a 2-byte struct passed as a 4-byte int on Wasm. Here the value is 2 bytes, the segment offset 0, and segment size is 4.

  6. added this to the 11.0.0 milestone on Mar 15, 2026
  7. added
    arch-wasm
    on Mar 15, 2026
  8. dotnet-policy-service commented on Mar 15, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
    See info in area-owners.md if you want to be subscribed.

  9. removed
    untriaged
    on Mar 15, 2026
  10. AndyAyersMS commented on May 15, 2026

    @AndyAyersMS
    MemberAuthor

    This was fixed by @kg's RS above.

  11. locked and limited conversation to collaborators on Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-wasmarea-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions