Skip to content

JIT: (bug) wrong result when a masked vcvttpd2dq ymm -> xmm is embedded into a Vector128<long> ConditionalSelect (AVX-512) #137901

Description

@EgorBo

On AVX-512VL hardware, a Vector128<long> ConditionalSelect with Avx.ConvertToVector128Int32WithTruncation(Vector256<double>) as its true operand gets folded into EVEX embedded masking on vcvttpd2dq xmm {k}, ymm. The mask has 2 qword lanes, but the instruction masks 4 dword lanes, so dwords 2..3 come from the false operand.

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<long> Test(Vector256<double> d, Vector128<long> a, Vector128<long> b, Vector128<long> c)
    {
        Vector128<long> conv = Avx.ConvertToVector128Int32WithTruncation(d).AsInt64();
        return Vector128.ConditionalSelect(Vector128.GreaterThan(a, b), conv, c);
    }

    static void Main()
    {
        Vector256<double> d = Vector256.Create(1.0, 2.0, 3.0, 4.0);
        Vector128<long> a = Vector128.Create(1L, 1L);
        Vector128<long> b = Vector128.Create(0L, 0L);
        Vector128<long> c = Vector128.Create(-1L, -1L);
        Console.WriteLine(Test(d, a, b, c).AsInt32());
    }
}

Expected

<1, 2, 3, 4>

Actual

<1, 2, -1, -1>

The output is correct with DOTNET_JITMinOpts=1 or DOTNET_EnableAVX512=0. Codegen:

       vpcmpgtq k1, xmm0, xmmword ptr [r9]       ; 2-lane (qword) mask
       vmovups  xmm0, xmmword ptr [rax]          ; c
       vcvttpd2dq xmm0 {k1}, ymmword ptr [rdx]   ; 4 dword lanes masked by k1 bits 0..3

Regression?

Reproduces on current main (Checked) and on the official 12.0.0-alpha.1.26557.102 build. The original report says .NET 10.0.15 doesn't reproduce (not re-verified).

Notes

ContainCheckHWIntrinsic (lowerxarch.cpp) computes tgtMaskSize = simdSize / genTypeSize(simdBaseType) (2), and GenTree::isEmbeddedMaskingCompatible accepts it. For the narrowing vcvttpd2dq/vcvtpd2dq with a 256-bit source, however, the write mask applies per destination dword (4 lanes). Embedded masking should be rejected for these narrowing conversions, or the mask lane count should be derived from the destination element size.

Activity

  1. added this to the 12.0.0 milestone on Nov 19, 2026
  2. added
    area-CodeGen-coreclr
    on Nov 19, 2026
  3. dotnet-policy-service commented on Nov 19, 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 Nov 24, 2026
  5. added a commit that references this issue on Nov 25, 2026
    bd5bccc
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