Skip to content

JIT: (bug) [ARM64] TryLowerCselToCSOp creates GT_SELECT_NEG/INV/INC with a register condition, which LSRA cannot build (wrong code in Release) #134056

Closed

Description

@EgorBo

When TryLowerConditionToFlagsNode bails out (CCMP chain longer than its 10-node look-back), the select keeps a register condition, but Lowering::TryLowerCselToCSOp still converts it to the GTK_SPECIAL GT_SELECT_NEG/_INV/_INC. LSRA has no BuildSelect path for those opers, so Checked asserts and Release emits a csneg/csinv reading a vector register — silent wrong results. .NET 11 regression.

Minimal Repro

using System;
using System.Runtime.CompilerServices;

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

    // Same shape with `~a` hits GT_SELECT_INV; `? 5 : 4` hits GT_SELECT_INC.
    static void Main() => Console.WriteLine(Test(3, 7)); // expected -3
}

Exactly 12 &-ed comparisons are needed; with 2..11 the JIT produces correct code.

Expected

-3

Actual

Release arm64 (deterministic, 3/3 runs):

0

Checked arm64:

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

Release codegen ends with:

            cset    x0, gt
            cmp     w0, #0
            mov     q0, w0              ; value moved into a *vector* register
            csneg   w0, w1, q0, ne      ; vector register used as a GPR source operand

The ~a variant returns -1 instead of -4 with mov q0, w0 / csinv w0, w1, q0, ne.

Notes

SELECT_INC/SELECT_INV/SELECT_NEG are GTK_SPECIAL in gtlist.h (their *CC siblings are
GTK_BINOP), and LinearScan::BuildNode on arm64 only routes GT_SELECT/GT_SELECTCC to
BuildSelect; the rest fall through to BuildSimple, which never builds uses for gtCond/the false
arm. genCodeForSelect does handle these opers, so the gap is purely LSRA plus the lowering contract.
Fix direction: either handle the non-CC GT_SELECT_* opers in LSRA, or have TryLowerCselToCSOp /
TryLowerCnsIntCselToCinc bail out when the select was not converted to GT_SELECTCC.

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