Skip to content

JIT: (bug) Vector128.Equals(Avx.Compare(a, b, UnorderedEqual*/OrderedNotEqual*), Zero) produces bad IR on AVX-512 (assert / wrong result / illegal instruction) #134480

Closed

Description

@EgorBo

On AVX-512 hardware, Equals(Compare(...), Zero) is morphed into a NOT whose result is a TYP_MASK node that is no longer wrapped in ConvertMaskToVector. The result is an assert, a wrong result, or an illegal instruction.

Minimal Repro

using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

public class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static Vector128<int> Test(Vector128<float> a, Vector128<float> b) =>
        Vector128.Equals(Avx.Compare(a, b, FloatComparisonMode.UnorderedEqualNonSignaling).AsInt32(), Vector128<int>.Zero);

    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static Vector256<int> Test2(Vector256<float> a, Vector256<float> b) =>
        Vector256.Equals(Avx.Compare(a, b, FloatComparisonMode.OrderedNotEqualNonSignaling).AsInt32(), Vector256<int>.Zero);

    public static void Main()
    {
        Vector128<float> a = Vector128.Create(1f, 2f, 3f, 4f);
        Vector128<float> b = Vector128.Create(1f, 0f, 3f, 0f);
        Console.WriteLine(Test(a, b));
        Console.WriteLine(Test2(Vector256.Create(a, a), Vector256.Create(b, b)));
    }
}

Expected

<0, -1, 0, -1>
<-1, 0, -1, 0, -1, 0, -1, 0>

Actual

Checked:

Assert failure: Assertion failed 'varTypeIsSIMD(op1)' in 'Program:Test(...)' during 'Morph - Global'
    File: src\coreclr\jit\gentree.cpp:24477

Release:

<5, 0, 0, 0>
Fatal error.
System.ExecutionEngineException: Illegal instruction: Attempted to execute an instruction code not defined by the processor.
   at Program.Test2(...)

Regression?

Yes, a regression in .NET 10. .NET 8 and 9 give the correct result. .NET 10, 11 RC2 and main fail.

Notes

The bug needs AVX-512 hardware; with DOTNET_EnableAVX512=0 the output is correct. fgMorphHWIntrinsicRequired turns EQ(mask, Zero) into ~op1. The GT_NOT case in fgOptimizeHWIntrinsic then peels ConvertMaskToVector, and in the NI_AVX512_CompareMask mode-reversal path (and the ~(~v) path) returns the TYP_MASK node without re-wrapping it in cvtIntrin.

Activity

  1. added this to the 12.0.0 milestone on Sep 22, 2026
  2. added
    area-CodeGen-coreclr
    on Sep 22, 2026
  3. dotnet-policy-service commented on Sep 22, 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 23, 2026
    2af9a56
  5. locked and limited conversation to collaborators on Oct 24, 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