Skip to content

JIT: (bug) [ARM64] TryLowerCnsIntCselToCinc keeps the wrong constant as the CINC base and produces an unusable GT_SELECT_INC #134055

Closed

Description

@EgorBo

On arm64, TryLowerCnsIntCselToCinc converts a register-conditioned GT_SELECT of two adjacent constants into GT_SELECT_INC, which LSRA cannot build (Checked assert, silent MinOpts fallback in Release). The GT_SELECT branch also keeps the larger constant as the CINC base, unlike the GT_SELECTCC branch.

Minimal Repro

using System;
using System.Runtime.CompilerServices;

class Prog
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static int Test(int a) =>
        (a > 0 & a > 1 & a > 2 & a > 3 & a > 4 & a > 5 & a > 6 & a > 7 & a > 8 & a > 9 & a > 10 & a > 11) ? 5 : 4;

    static void Main() => Console.WriteLine(Test(100) + " " + Test(0)); // expected: 5 4
}

The 12-element & chain is required so the CCMP walk-back exceeds the 10-node limit in
TryLowerConditionToFlagsNode and the node stays a register-condition GT_SELECT.

Expected

5 4, compiled with FullOpts into a csinc-style sequence (~84 bytes, as in the ? 7 : 4 control case).

Actual

Checked arm64:

Assertion failed '(kind & GTK_SMPOP) != 0' in 'Prog:Test(int):int' during 'Linear scan register alloc'
    File: src/coreclr/jit/lsrabuild.cpp:4221

With DOTNET_JitDump an earlier '!"unhandled special node"' assert fires in compiler.hpp:4448.
Release arm64 silently abandons FullOpts and re-jits with MinOpts: 228 bytes vs 84 bytes for the
? 7 : 4 control case. Same MinOpts cliff on shipped .NET 10.0.9.

Notes

lowerarmarch.cpp, TryLowerCnsIntCselToCinc, GT_SELECT branch: with op1Val = 5, op2Val = 4,
shouldReverseCondition is false, gtOp2 (4) is removed and gtOp1 (5) stays as the CINC base, so
genCodeForSelect would emit cond ? 6 : 5. The GT_SELECTCC branch just below does the required
std::swap(gtOp1, gtOp2); the GT_SELECT branch does not. This wrong value is currently masked
because GT_SELECT_INC is GTK_SPECIAL and never survives LSRA (see the related register-condition
CSOp contract issue), but fixing only the backend would turn it into silent wrong code.

Activity

  1. added this to the 12.0.0 milestone on Sep 16, 2026
  2. added
    area-CodeGen-coreclr
    on Sep 16, 2026
  3. dotnet-policy-service commented on Sep 16, 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. self-assigned this
    on Oct 12, 2026
  5. added a commit that references this issue on Oct 14, 2026
    506ef9c
  6. locked and limited conversation to collaborators on Nov 13, 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