Skip to content

JIT: (bug) Loop cloning builds a small-typed GT_ADD for a ushort limit base with a constant offset #133761

Closed

Description

@EgorBo

Minimal repro

using System;
using System.Runtime.CompilerServices;

public static class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static int Test(int[] a, ushort src)
    {
        ushort n = src;
        int sum = 0;
        for (int i = 0; i < n + 1000; i++)
        {
            sum += a[i];
        }
        return sum;
    }

    public static int Main()
    {
        int[] a = new int[70000];
        for (int i = 0; i < a.Length; i++) a[i] = 1;
        int actual = Test(a, 65000);
        int expected = 66000;
        Console.WriteLine($"Expected: {expected} Actual: {actual}");
        return actual == expected ? 100 : 1;
    }
}

Run: corerun repro.dll (Checked or Release JIT, .NET 11 main @ b44cd90)

Expected

Exit code 100 / prints Expected: 66000 Actual: 66000

Actual

[000079] -----------                         *  ADD       ushort
               [000077] -----------                         +--*  LCL_VAR   ushort V02 loc0
               [000078] -----------                         \--*  CNS_INT   int    0x3E8

Assert failure(PID 42944 [0x0000a7c0], Thread: 43616 [0xaa60]): Assertion failed '!"Unexpected small type in IR"' in 'Program:Test(int[],ushort):int' during 'Clone loops' (IL size 30; hash 0xb990678b; FullOpts)
    File: C:\prj\runtime-main3\src\coreclr\jit\fgdiagnostic.cpp:3587

Notes

No env knobs needed. LC_Ident::ToGenTree (loopcloning.cpp:169-173) builds the offset GT_ADD with lvaTable[lclNum].lvType instead of genActualType.

Activity

  1. added this to the 12.0.0 milestone on Sep 11, 2026
  2. added
    area-CodeGen-coreclr
    on Sep 11, 2026
  3. dotnet-policy-service commented on Sep 11, 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. added a commit that references this issue on Sep 14, 2026
    503b6ad
  5. added a commit that references this issue on Sep 18, 2026
    305dd61
  6. locked and limited conversation to collaborators on Oct 15, 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-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions