Skip to content

JIT: (bug) BlendVariable on float ignores the sign-bit rule when the mask is byte-granular #133548

Closed

Description

@EgorBo

Repro

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

class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static uint Test(Vector128<float> value, Vector128<byte> l, Vector128<byte> r) =>
        Sse41.BlendVariable(Vector128<float>.Zero, value, Sse2.CompareEqual(l, r).AsSingle())
             .AsUInt32().GetElement(0);

    static void Main()
    {
        if (!Sse41.IsSupported)
            throw new PlatformNotSupportedException("SSE4.1 is required.");

        // Bytes 0 and 1 compare equal (0xFF), bytes 2 and 3 do not (0x00), so the first
        // 32-bit mask lane is 0x0000FFFF and its sign bit is clear. blendvps selects per
        // 32-bit lane using only that lane's sign bit, so lane 0 must come from Zero.
        var l = Vector128.Create((byte)1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        var r = Vector128.Create((byte)1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        var value = Vector128.Create(0x12345678u).AsSingle();

        Console.WriteLine(Test(value, l, r).ToString("X8"));
    }
}

Expected

00000000

Actual

00005678

The result is value & mask computed bitwise, which is neither of the two operands blendvps
is allowed to select.

Platform

Windows x64, local Checked build of dotnet/runtime main (ef97eb5). Requires SSE4.1; also
reproduces with DOTNET_EnableAVX512=0 and DOTNET_EnableAVX=0.

Activity

  1. added this to the 12.0.0 milestone on Sep 10, 2026
  2. added
    area-CodeGen-coreclr
    on Sep 10, 2026
  3. dotnet-policy-service commented on Sep 10, 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 15, 2026
    ae47da8
  5. EgorBo commented on Sep 18, 2026

    @EgorBo
    MemberAuthor

    Affected SDK versions:

    • 11.0.100-rc.2.26467.112
  6. added a commit that references this issue on Sep 18, 2026
    8881272
  7. EgorBo commented on Sep 18, 2026

    @EgorBo
    MemberAuthor

    @tannergooding would you consider backporting the fix from #133708 to release/11.0?

    It currently only exists in main (12.0). The repro still fails on the shipped 11.0 RC2 SDK (11.0.100-rc.2.26467.112), while 8.0.425, 9.0.318 and 10.0.401 all behave correctly, so this is a regression introduced during the 11.0 cycle rather than a long-standing bug — 11.0 would ship with it.

    Note: this comment was produced by an AI agent; the repro was re-run against all four released SDKs to confirm the results above.

  8. locked and limited conversation to collaborators on Oct 19, 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