Skip to content

JIT: [runtime async] Assertion failed '(attrSize == EA_4BYTE) || (attrSize == EA_PTRSIZE) || (attrSize == EA_16BYTE) || (attrSize == EA_32BYTE) || (attrSize == EA_64BYTE) || (ins == INS_movzx) || (ins == INS_movsx) || (ins == INS_cmpxchg) || isPrefetch(ins)' in 'C0:M1():ushort:this' during 'Generate code' #118921

Closed

Description

@jakobbotsch
// Generated by Fuzzlyn v3.3 on 2025-08-20 11:20:11
// Run on X86 Windows
// Seed: 2926786485972810815-async,runtimeasync,vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86bmi1,x86bmi2,x86fma,x86lzcnt,x86pclmulqdq,x86popcnt,x86sse,x86sse2,x86sse3,x86sse41,x86sse42,x86ssse3,x86x86base
// Reduced from 44.4 KiB to 1.1 KiB in 00:03:01
// Hits JIT assert for Release with Runtime Async:
// Assertion failed '(attrSize == EA_4BYTE) || (attrSize == EA_PTRSIZE) || (attrSize == EA_16BYTE) || (attrSize == EA_32BYTE) || (attrSize == EA_64BYTE) || (ins == INS_movzx) || (ins == INS_movsx) || (ins == INS_cmpxchg) || isPrefetch(ins)' in 'C0:M1():ushort:this' during 'Generate code' (IL size 115; hash 0x7c6ce310; FullOpts)
// 
//     File: D:\a\_work\1\s\src\coreclr\jit\emitxarch.cpp Line: 5395
// 
using System.Threading.Tasks;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

public class C0
{
    public ulong F1;
    public ushort F4;
    public async Task<ushort> M1()
    {
        C0[] var2 = default(C0[]);
        for (uint lvar1 = 4294967290U; lvar1 < 4294967292U; lvar1++)
        {
            var vr7 = var2[0];
            var vr6 = await Program.M3(vr7);
            var vr11 = Vector128.Create<int>(0);
            var vr10 = (sbyte)Sse41.Extract(vr11, 0);
            var vr9 = Vector256.Create<sbyte>(vr10);
            var vr12 = Vector256.Create(0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            var vr8 = Avx512BW.VL.CompareGreaterThanOrEqual(vr9, vr12);
            var2[0].F1 = (ulong)Avx2.MoveMask(vr8);
        }

        return this.F4;
    }
}

public class Program
{
    public static void Main()
    {
        M0().GetAwaiter().GetResult();
    }

    public static async Task M0()
    {
        await (new C0()).M1();
    }

    public async static Task<uint> M3(C0 argThis)
    {
        return 0;
    }
}

Activity

  1. added
    untriaged
    on Aug 20, 2025
  2. changed the title [-]JIT: (attrSize == EA_4BYTE) || (attrSize == EA_PTRSIZE) || (attrSize == EA_16BYTE) || (attrSize == EA_32BYTE) || (attrSize == EA_64BYTE) || (ins == INS_movzx) || (ins == INS_movsx) || (ins == INS_cmpxchg) || isPrefetch(ins)[/-] [+]JIT: Assertion failed '(attrSize == EA_4BYTE) || (attrSize == EA_PTRSIZE) || (attrSize == EA_16BYTE) || (attrSize == EA_32BYTE) || (attrSize == EA_64BYTE) || (ins == INS_movzx) || (ins == INS_movsx) || (ins == INS_cmpxchg) || isPrefetch(ins)' in 'C0:M1():ushort:this' during 'Generate code'[/+] on Aug 20, 2025
  3. added
    area-CodeGen-coreclr
    on Aug 20, 2025
  4. dotnet-policy-service commented on Aug 20, 2025

    @dotnet-policy-service
    Contributor

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

  5. changed the title [-]JIT: Assertion failed '(attrSize == EA_4BYTE) || (attrSize == EA_PTRSIZE) || (attrSize == EA_16BYTE) || (attrSize == EA_32BYTE) || (attrSize == EA_64BYTE) || (ins == INS_movzx) || (ins == INS_movsx) || (ins == INS_cmpxchg) || isPrefetch(ins)' in 'C0:M1():ushort:this' during 'Generate code'[/-] [+]JIT: [runtime async] Assertion failed '(attrSize == EA_4BYTE) || (attrSize == EA_PTRSIZE) || (attrSize == EA_16BYTE) || (attrSize == EA_32BYTE) || (attrSize == EA_64BYTE) || (ins == INS_movzx) || (ins == INS_movsx) || (ins == INS_cmpxchg) || isPrefetch(ins)' in 'C0:M1():ushort:this' during 'Generate code'[/+] on Aug 20, 2025
  6. removed
    untriaged
    on Aug 20, 2025
  7. added this to the 10.0.0 milestone on Aug 20, 2025
  8. jakobbotsch commented on Aug 21, 2025

    @jakobbotsch
    MemberAuthor

    Attached SPMI collection on fad7576

    col.zip

  9. jakobbotsch commented on Aug 21, 2025

    @jakobbotsch
    MemberAuthor

    Here we have a TYP_MASK local that is live across a suspension point. Runtime async thus saves it to memory across the suspension, and the backend asserts when it sees the mask-typed STOREIND:

    N001 (  3,  2) [000563] -----------                  t563 =    LCL_VAR   ref    V27 rat7         
    N002 (  1,  1) [000565] -----------                  t565 =    CNS_INT   int    16
                                                                ┌──▌  t563   ref    
                                                                ├──▌  t565   int    
    N003 (  4,  3) [000566] -------N---                  t566 = ▌  ADD       byref 
    N004 (  3,  2) [000564] -----------                  t564 =    LCL_VAR   mask   V18 cse1         
                                                                ┌──▌  t566   byref  
                                                                ├──▌  t564   mask   
    N005 ( 10,  8) [000567] nA--G------                         ▌  STOREIND  mask   (copy)
    

    Seems to work fine on x64. @tannergooding there is nothing fundamentally preventing storing a mask variable like this to memory, right?

  10. JulieLeeMSFT commented on Sep 2, 2025

    @JulieLeeMSFT
    Member
  11. jakobbotsch commented on Sep 10, 2025

    @jakobbotsch
    MemberAuthor

    I will move this to .NET 11. Runtime async is experimental and I think it is ok if there are rough edges in the intersection between runtime async and mask based hardware intrinsics.

  12. modified the milestones: 10.0.0, 11.0.0 on Sep 10, 2025
  13. tannergooding commented on Sep 10, 2025

    @tannergooding
    Member

    Sorry, missed the tag.

    Seems to work fine on x64. @tannergooding there is nothing fundamentally preventing storing a mask variable like this to memory, right?

    Correct, nothing prevents it and its required for things like calls since all mask registers are volatile.

    This should simply be a kmovq [mem], k1 and when the suspend is done a kmovq k1, [mem] (using appropriate register, of course).

  14. tannergooding commented on Sep 10, 2025

    @tannergooding
    Member

    We should have one of:

    KMOVB: VEX.L0.66.0F.W0 90/91,    c5 f9 91 4c 24 40
    KMOVW: VEX.L0.0F.W0 90/91,       c5 f8 91 4c 24 40
    KMOVD: VEX.L0.66.0F.W1 90/91,    c4 e1 f9 91 4c 24 40
    KMOVQ: VEX.L0.0F.W1 90/91,       c4 e1 f8 91 4c 24 40
    

    The way the instructions work for SIMD is a bit interesting where the lookup tables have them "unprefixed" and so we'd have 0x0F91 or 0x0F6691 as the code. We then call emitGetAdjustedSize which is supposed to "fix" this based on the encoding we'll actually end up using (such as VEX or EVEX).

    It looks like we'd hit this path for KMOVB or KMOVQ, which likely has been untested due to there not being TYP_MASK fields since its a synthetic JIT only type and so we'd only ever spill to the stack before. Most other paths (like emitInsSizeSV and emitInsSizeCV) just reuse emitInsSize where-as emitInsSizeAM has its own logic (which looks largely unnecessary since it's really just emitInsSize + addressing mode sizing).

    The short term fix would be to just include the kmov instructions here as well in the assert. The long term "better" fix would be to update emitInsSizeAM to just reuse emitInsSize like everything else does and then simply compute the addressing mode requirements as additional on that (modR/M byte, if any displacement exists, etc). -- The special handling for cmpxchg "should" be generally handled elsewhere since that'd be required for 16-bit stack accesses and otherwise can remain special cased as an addition on top of emitInsSize just for the emitInsSizeAM path, so we have less duplicated logic.

  15. jakobbotsch commented on Sep 10, 2025

    @jakobbotsch
    MemberAuthor

    Thanks @tannergooding. Does it mean you think this is only an assertion problem?

    To be clear, we don't see these asserts on x64, and it appears things are working correctly there. So only x86 is affected, and it sounds like it might even be working fine in release builds there.

  16. tannergooding commented on Sep 10, 2025

    @tannergooding
    Member

    Does it mean you think this is only an assertion problem?

    At least at a glance it looks like an assert problem. I'm a bit surprised that its only occurring for x86, but that might be due to kmovq being a special instruction that supports a 64-bit memory read/write even in 32-bit mode (much like movq does).

  17. jakobbotsch commented on Sep 11, 2025

    @jakobbotsch
    MemberAuthor

    Maybe the assert just passes on x64 since it includes a check against EA_PTRSIZE? I think the mask size was 8 bytes when I looked.

  18. tannergooding commented on Sep 11, 2025

    @tannergooding
    Member

    Maybe the assert just passes on x64 since it includes a check against EA_PTRSIZE? I think the mask size was 8 bytes when I looked.

    That looks to be the case. The assert is:

    assert((attrSize == EA_4BYTE) || (attrSize == EA_PTRSIZE)                               // Only for x64
                   || (attrSize == EA_16BYTE) || (attrSize == EA_32BYTE) || (attrSize == EA_64BYTE) // only for x64
                   || (ins == INS_movzx) || (ins == INS_movsx) ||
                   (ins == INS_cmpxchg)
                   // The prefetch instructions are always 3 bytes and have part of their modr/m byte hardcoded
                   || isPrefetch(ins));
    

    So this is basically boiling down to "only fail for EA_1/2BYTE if the instruction isn't movzx/movsx/cmpxchg/prefetch"

    While for x86 it also extends to EA_8BYTE since we don't normally support that on 32-bit.

  19. locked and limited conversation to collaborators on Oct 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrruntime-async

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions