Skip to content

JIT: wrong result with Avx512BW.BlendVariable #114922

@BruceForstall

Description

@BruceForstall
// Generated by Fuzzlyn v2.5 on 2025-04-22 17:33:23
// Run on X64 Windows
// Seed: 5065841368374928084-vectort,vector128,vector256,vector512,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86avx512vbmi,x86avx512vbmivl,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base
// Reduced from 351.2 KiB to 1.3 KiB in 00:03:48
// Debug: Outputs <0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>
// Release: Outputs <0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>
using System;
using System.Numerics;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

public class Program
{
    public static IRuntime s_rt;
    public static ushort s_10;
    public static void Main()
    {
        s_rt = new Runtime();
        Vector512<ushort>[][] vr24 = new Vector512<ushort>[][]
        {
            new Vector512<ushort>[]
            {
                Vector512.Create<ushort>(1)
            }
        };
        var vr25 = (sbyte)0;
        var vr26 = Vector256.CreateScalar(vr25);
        var vr27 = Avx512BW.ConvertToVector512UInt16(vr26);
        var vr28 = Vector512.Create<ushort>(1);
        var vr29 = Vector128.Create<ushort>(s_10);
        var vr30 = Avx512F.InsertVector128(vr28, vr29, 0);
        var vr31 = vr24[0][0];
        var vr32 = Vector512.Create(1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 63696, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0);
        var vr33 = Avx512BW.MultiplyLow(vr31, vr32);
        Vector512<ushort> vr23 = Avx512BW.BlendVariable(vr27, vr30, vr33);
        s_rt.WriteLine(vr23);
    }
}

public interface IRuntime
{
    void WriteLine<T>(T value);
}

public class Runtime : IRuntime
{
    public void WriteLine<T>(T value) => System.Console.WriteLine(value);
}

another case:

// Generated by Fuzzlyn v2.5 on 2025-04-22 17:40:04
// Run on X64 Windows
// Seed: 541182799536624154-vectort,vector128,vector256,vector512,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86avx512vbmi,x86avx512vbmivl,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base
// Reduced from 69.1 KiB to 1.0 KiB in 00:00:41
// Debug: Outputs <1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1>
// Release: Outputs <1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1>
using System;
using System.Numerics;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

public class Program
{
    public static IRuntime s_rt;
    public static void Main()
    {
        s_rt = new Runtime();
        var vr5 = Vector512.Create<sbyte>(1);
        var vr6 = Vector512.Create<sbyte>(0);
        var vr7 = Vector128.Create(0, 1, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1);
        var vr8 = Avx512F.InsertVector128(vr6, vr7, 0);
        var vr9 = Vector512.Create(0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        Vector512<sbyte> vr10 = Avx512BW.BlendVariable(vr5, vr8, vr9);
        s_rt.WriteLine(vr10);
    }
}

public interface IRuntime
{
    void WriteLine<T>(T value);
}

public class Runtime : IRuntime
{
    public void WriteLine<T>(T value) => System.Console.WriteLine(value);
}

another case:

// Generated by Fuzzlyn v2.5 on 2025-04-22 17:40:46
// Run on X64 Windows
// Seed: 5475524594276290114-vectort,vector128,vector256,vector512,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86avx512vbmi,x86avx512vbmivl,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base
// Reduced from 34.9 KiB to 0.9 KiB in 00:00:32
// Debug: Outputs <-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1>
// Release: Outputs <-1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1>
using System;
using System.Numerics;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

public struct S1
{
    public sbyte F5;
    public sbyte F8;
    public S1(sbyte f5, sbyte f8) : this()
    {
        F5 = f5;
        F8 = f8;
    }
}

public class Program
{
    public static S1[,, ][] s_1 = new S1[,, ][]
    {
        {
            {
                new S1[]
                {
                    new S1(-1, 1)
                }
            }
        }
    };
    public static void Main()
    {
        var vr5 = s_1[0, 0, 0][0].F5;
        Vector512<sbyte> vr6 = Vector512.CreateScalar(vr5);
        var vr7 = s_1[0, 0, 0][0].F8;
        var vr8 = Vector512.Create<sbyte>(vr7);
        var vr9 = s_1[0, 0, 0][0].F8;
        var vr10 = Vector128.Create<sbyte>(vr9);
        vr6 = Avx512BW.BlendVariable(vr8, Avx512F.InsertVector128(vr6, vr10, 1), vr6);
        System.Console.WriteLine(vr6);
    }
}

Possible dup of #114921

cc @dotnet/jit-contrib @dotnet/intel

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIavx512Related to the AVX-512 architecture

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions