Skip to content

JIT: Assertion failed '!"Write to unaliased local overlaps outstanding read"' during 'Rationalize IR' with AVX intrinsics #124749

Closed

Description

@jakobbotsch
// Generated by Fuzzlyn v3.3 on 2026-02-22 16:38:42
// Run on X64 Windows
// Seed: 12524694341177432228-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base
// Reduced from 40.5 KiB to 0.6 KiB in 00:01:15
// Hits JIT assert for Release:
// Assertion failed '!"Write to unaliased local overlaps outstanding read"' in 'Program:M0()' during 'Rationalize IR' (IL size 61; hash 0xaf50ff37; FullOpts)
// 
//     File: D:\a\_work\1\s\src\coreclr\jit\lir.cpp Line: 1502
// 
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

public class Program
{
    public static byte[] s_2;
    public static void Main()
    {
        M0();
    }

    public static void M0()
    {
        var vr1 = Vector256.CreateScalar(1U);
        var vr3 = Vector256.Create<uint>(1);
        var vr5 = Vector256.Create<uint>(0);
        var vr7 = Vector256.Create<uint>(1);
        var vr6 = Avx512CD.VL.LeadingZeroCount(vr7);
        var vr4 = Avx2.CompareEqual(vr5, vr6);
        var vr2 = Avx2.Subtract(vr3, vr4);
        if (Avx.TestZ(vr1, vr2))
        {
            var vr0 = s_2[0];
        }
    }
}

Output:

read:  N001 (  1,  1) [000049] -----------                   t49 =    LCL_VAR   simd32 V05 cse0         u:1 $c0
       N002 (  3,  2) [000007] -----------                    t7 =    CNS_VEC   simd32<0x0000000100000001, 0x0000000100000001, 0x0000000100000001, 0x0000000100000001> $c0
                                                                   ┌──▌  t7     simd32
write: N003 (  3,  3) [000046] DA---------                         ▌  STORE_LCL_VAR simd32 V05 cse0         d:1 $VN.Void
       N004 (  1,  2) [000052] -----------                   t52 =    CNS_MSK   mask  <0x00000000, 0x00000000> $140
                                                                   ┌──▌  t52    mask
       N006 (  5,  6) [000012] -A---------                   t12 = ▌  HWINTRINSIC simd32 32 uint ConvertMaskToVector $180
                                                                   ┌──▌  t49    simd32
                                                                   ├──▌  t12    simd32
user:  N007 (  7,  8) [000015] -A---------                   t15 = ▌  HWINTRINSIC simd32 32 uint Subtract $1c1
       N008 (  3,  2) [000001] -----------                    t1 =    CNS_VEC   simd32<0x0000000000000001, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000> $c3
                                                                   ┌──▌  t1     simd32
                                                                   ├──▌  t15    simd32
       N009 ( 11, 11) [000018] -A---------                   t18 = ▌  HWINTRINSIC int    32 uint TestZ $200
       N010 (  1,  1) [000019] -----------                   t19 =    CNS_INT   int    0 $43
                                                                   ┌──▌  t18    int
                                                                   ├──▌  t19    int
       N011 ( 13, 13) [000020] JA-----N---                   t20 = ▌  EQ        int    $240
                                                                   ┌──▌  t20    int
       N012 ( 15, 15) [000021] -A---------                         ▌  JTRUE     void   $VN.Void

Attached SPMI collection collected on 5302011.
col.zip

cc @dotnet/jit-contrib

Activity

  1. added
    untriaged
    on Feb 23, 2026
  2. added
    area-CodeGen-coreclr
    on Feb 23, 2026
  3. dotnet-policy-service commented on Feb 23, 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. removed
    untriaged
    on Feb 23, 2026
  5. added this to the 11.0.0 milestone on Feb 23, 2026
  6. added
    avx512
    on Apr 17, 2026
  7. JulieLeeMSFT commented on Apr 17, 2026

    @JulieLeeMSFT
    Member

    @Ruihan-Yin, PTAL.
    cc @kg

  8. AndyAyersMS commented on Jun 15, 2026

    @AndyAyersMS
    Member

    Note

    This comment was AI-generated.

    Still reproducing on main as of build 1453110 (Fuzzlyn run 2026-06-07). Same hash 0xaf50ff37, same method Program:M0(), same assertion at src/coreclr/jit/lir.cpp:1502. New 0.9 KiB repro (uses runtime async + an extra Avx2.SubtractSaturate indirection that causes an assertion-prop re-morph to re-trigger the Add(Sub(0,X), Y) -> Sub(Y, X) identity after CSE has placed a COMMA def in X):

    // Generated by Fuzzlyn v3.3 on 2026-06-07 17:13:00
    // Run on X64 Windows
    // Seed: 15567831524342187378-async,runtimeasync,vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base
    // Reduced from 38.0 KiB to 0.9 KiB in 00:01:16
    // Hits JIT assert for Release with Runtime Async:
    // Assertion failed '!"Write to unaliased local overlaps outstanding read"' in 'Program:M0()' during 'Rationalize IR' (IL size 22; hash 0xaf50ff37; FullOpts)
    //
    //     File: D:\a\_work\1\s\src\coreclr\jit\lir.cpp Line: 1502
    //
    using System.Threading.Tasks;
    using System.Runtime.Intrinsics;
    using System.Runtime.Intrinsics.X86;
    
    public struct S0
    {
        public S0(int f0) : this()
        {
        }
    }
    
    public class Program
    {
        public static void Main()
        {
            M0().GetAwaiter().GetResult();
        }
    
        public static async Task M0()
        {
            var vr2 = new S0((ushort)(await M2(false, 1)));
        }
    
        public static async Task<long> M2(bool arg1, short arg2)
        {
            var vr1 = (short)0;
            var vr0 = Vector256.CreateScalar(vr1);
            var vr5 = Vector256.Create<short>(arg2);
            var vr7 = Vector256.Create<short>(0);
            var vr8 = Vector256.Create<short>(arg2);
            var vr6 = Avx2.SubtractSaturate(vr7, vr8);
            var vr4 = Avx2.Subtract(vr5, vr6);
            arg1 |= Avx.TestZ(vr0, vr4);
            System.Console.WriteLine(arg1);
            return 0;
        }
    }
    Analysis of jitdump (AI generated)

    The assertion fires in BB07/STMT00019 of the inlined M2 body inside the
    runtime-async wrapper Program:M0().

    1. Morph (initial) rewrites Avx2.Subtract(vr5, vr6) into
      Add(Subtract(0, vr6), vr5) via the SIMD identity (0 - b) + a == a - b.
      vr5 and vr8 both fold to CNS_VEC<0x0001...> with shared VN $281.

    2. CSE picks them as CSE WIP: repo consolidation scouting kick-off - make clr build locally on Windows #1 (V29), wraps the
      leftmost-in-eval-order occurrence (inside SubtractSaturate) in
      COMMA(STORE_LCL_VAR V29 = CNS_VEC, LCL_VAR V29), and rewrites the
      other occurrence (the Add's right operand) as a bare LCL_VAR V29 use.
      Post-CSE HIR eval order is fine: COMMA def at N002 precedes bare use
      at N009.

    3. Assertion prop's re-morph re-applies the same identity on the new
      Add(Sub(0, X), Y) tree, producing Sub(Y, X) where:

      • Y is the bare LCL_VAR V29 (now the left operand of Sub)
      • X is SubtractSaturate(0, COMMA(STORE V29, LCL_VAR V29)) (now the
        right operand of Sub)

      In HIR exec order this places the bare LCL_VAR V29 read at N001,
      before the STORE_LCL_VAR V29 at N003.

    4. Rationalize linearizes faithfully; lir.cpp:1502 detects the
      outstanding read of V29 whose user (Subtract) is reached only
      after the intervening STORE_LCL_VAR V29 write, and asserts.

    Same root cause as the original repro — CSE plants a COMMA def in
    whichever operand it picked as first-evaluated, and a subsequent morph
    identity swaps the operand evaluation order without checking that the
    swap reorders a read of a CSE local before its only def.

    Repro .mc + jitdump.txt available on request.

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

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclravx512

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions