Skip to content

[Wasm RyuJit] prolog IG can overflow #125200

Closed

Description

@AndyAyersMS

Using repro instructions from #125199 with

--singlemethodtypename:"System.Runtime.Intrinsics.Vector256"
--singlemethodname:"Create" 
--singlemethodindex:17

we try and put too much code into the prolog IG

ebug: New V10 debug range: first
IN00c1:             local.cnt 0
IN00c2:             local.get 0
IN00c3:             i32.const 272
IN00c4:             i32.sub
IN00c5:             local.set 0
*************** In genHomeRegisterParams()
IN00c6:             local.get 0
IN00c7:             local.get 1
IN00c8:             i32.store 0 268      ;; V01
IN00c9:             local.get 0
IN00ca:             local.get 2
IN00cb:             i32.store 0 264      ;; V02
IN00cc:             local.get 0
IN00cd:             local.get 3
IN00ce:             i32.store 0 260      ;; V03
IN00cf:             local.get 0
IN00d0:             local.get 4
IN00d1:             i32.store 0 256      ;; V04
IN00d2:             local.get 0
IN00d3:             local.get 5
IN00d4:             i32.store 0 252      ;; V05
IN00d5:             local.get 0
IN00d6:             local.get 6
IN00d7:             i32.store 0 248      ;; V06
IN00d8:             local.get 0
IN00d9:             local.get 7
IN00da:             i32.store 0 244      ;; V07
IN00db:             local.get 0
IN00dc:             local.get 8
IN00dd:             i32.store 0 240      ;; V08
IN00de:             local.get 0
IN00df:             local.get 9
IN00e0:             i32.store 0 236      ;; V09
IN00e1:             local.get 0
IN00e2:             local.get 10
IN00e3:             i32.store 0 232      ;; V10
IN00e4:             local.get 0
IN00e5:             local.get 11
IN00e6:             i32.store 0 228      ;; V11
IN00e7:             local.get 0
IN00e8:             local.get 12
IN00e9:             i32.store 0 224      ;; V12
IN00ea:             local.get 0
IN00eb:             local.get 13
IN00ec:             i32.store 0 220      ;; V13
IN00ed:             local.get 0
IN00ee:             local.get 14
IN00ef:             i32.store 0 216      ;; V14
IN00f0:             local.get 0
IN00f1:             local.get 15
IN00f2:             i32.store 0 212      ;; V15
IN00f3:             local.get 0
IN00f4:             local.get 16
IN00f5:             i32.store 0 208      ;; V16
IN00f6:             local.get 0
IN00f7:             local.get 17
IN00f8:             i32.store 0 204      ;; V17
IN00f9:             local.get 0
IN00fa:             local.get 18
IN00fb:             i32.store 0 200      ;; V18
IN00fc:             local.get 0
IN00fd:             local.get 19
IN00fe:             i32.store 0 196      ;; V19
IN00ff:             local.get 0
IN0100:             local.get 20
IN0101:             i32.store 0 192      ;; V20
IN0102:             local.get 0
IN0103:             local.get 21
IN0104:             i32.store 0 188      ;; V21
IN0105:             local.get 0
IN0106:             local.get 22
IN0107:             i32.store 0 184      ;; V22
IN0108:             local.get 0
IN0109:             local.get 23
IN010a:             i32.store 0 180      ;; V23
IN010b:             local.get 0
IN010c:             local.get 24
IN010d:             i32.store 0 176      ;; V24
IN010e:             local.get 0
IN010f:             local.get 25
IN0110:             i32.store 0 172      ;; V25
IN0111:             local.get 0
IN0112:             local.get 26
IN0113:             i32.store 0 168      ;; V26
IN0114:             local.get 0
IN0115:             local.get 27
IN0116:             i32.store 0 164      ;; V27
IN0117:             local.get 0
IN0118:             local.get 28
C:\repos\runtime2\src\coreclr\jit\emit.cpp:9875
Assertion failed 'emitCurIG != emitPrologIG' in 'System.Runtime.Intrinsics.Vector256:Create(byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte,byte):System.Runtime.Intrinsics.Vector256`1[byte]' during 'Generate code' (IL size 81; hash 0x4b683611; MinOpts)

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. jakobbotsch commented on Mar 5, 2026

    @jakobbotsch
    Member

    Swift has a similar problem. It works around this backend limitation on the prolog size by doing it in the first basic block:

    #ifdef SWIFT_SUPPORT
    // Reassemble Swift struct parameters on the local stack frame in the
    // init BB right after the prolog. There can be arbitrary amounts of
    // codegen related to doing this, so it cannot be done in the prolog.
    if (block->IsFirst() && m_compiler->lvaHasAnySwiftStackParamToReassemble())
    {
    genHomeSwiftStructStackParameters();
    }
    #endif

  5. kg commented on Mar 10, 2026

    @kg
    Contributor

    I see multiple ways to fix this:

    1. Enlarge the IG buffer. This is already done conditionally for certain architectures, and doing it for Wasm the same way fixes this particular method
    2. Add multi-IG prolog support. I found a comment to the effect of 'we should really do this'
    3. Move this part of the prolog out of the prolog IG. That seems like it could have nasty side effects especially since only Wasm does it.

    I feel like for now we should just do option 1, and once that ceases to be enough, we should do 2. I don't think we should do 3.

  6. jakobbotsch commented on Mar 10, 2026

    @jakobbotsch
    Member

    3. Move this part of the prolog out of the prolog IG. That seems like it could have nasty side effects especially since only Wasm does it.

    Swift does the same as I pointed at above. I don't think it would be particularly weird to do it that way.

  7. kg commented on Mar 10, 2026

    @kg
    Contributor
    1. Move this part of the prolog out of the prolog IG. That seems like it could have nasty side effects especially since only Wasm does it.

    Swift does the same as I pointed at above. I don't think it would be particularly weird to do it that way.

    We would have to move the genHomeRegisterParams call out of its current position, or redefine what genHomeRegisterParams does, I think? This isn't limited to a specific subset of struct parameters for a specific calling convention.

  8. jakobbotsch commented on Mar 10, 2026

    @jakobbotsch
    Member
    1. Move this part of the prolog out of the prolog IG. That seems like it could have nasty side effects especially since only Wasm does it.

    Swift does the same as I pointed at above. I don't think it would be particularly weird to do it that way.

    We would have to move the genHomeRegisterParams call out of its current position, or redefine what genHomeRegisterParams does, I think? This isn't limited to a specific subset of struct parameters for a specific calling convention.

    genHomeRegisterParams is already different for wasm. It does not seem like a huge issue to make it do nothing and call the wasm specific handling next to the Swift handling instead.

  9. kg commented on Mar 10, 2026

    @kg
    Contributor

    Will try that, thanks. We don't have good test coverage yet so I'm wary of making big changes without someone who knows the JIT better saying 'that should work'.

  10. jakobbotsch commented on Mar 10, 2026

    @jakobbotsch
    Member

    To be clear I think 2 is a better solution, and if implemented we would move the Swift handling back into the prolog too. But as you point out, 1 is not much of a solution. At least with 3 we shouldn't need to come back to this problem (famous last words).

  11. added
    arch-wasm
    on Mar 15, 2026
  12. added this to the 11.0.0 milestone on Mar 15, 2026
  13. 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.

  14. removed
    untriaged
    on Mar 15, 2026
  15. AndyAyersMS commented on May 1, 2026

    @AndyAyersMS
    MemberAuthor

    Allowing multiple prolog IGs: #126552

  16. locked and limited conversation to collaborators on Aug 2, 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