Skip to content

JIT: (bug) AvxVnni.V512.MultiplyWideningAndAdd folded into BlendVariable loses the merge operand #133753

Description

@EgorBo

Minimal repro

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

public static class Program
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static Vector512<int> Test(Vector512<int> fallback, Vector512<int> addend,
                                      Vector512<byte> left, Vector512<sbyte> right,
                                      Vector512<int> a, Vector512<int> b)
    {
        Vector512<int> mask = Avx512F.CompareEqual(a, b);
        return Avx512F.BlendVariable(fallback, AvxVnni.V512.MultiplyWideningAndAdd(addend, left, right), mask);
    }

    public static void Main()
    {
        if (!AvxVnni.V512.IsSupported) { Console.WriteLine("unsupported"); return; }
        Console.WriteLine(Test(
            Vector512.Create(7),            // fallback
            Vector512.Create(5),            // addend (left*right == 0, so the product is 5)
            Vector512<byte>.Zero,
            Vector512<sbyte>.Zero,
            Vector512.Create(1),
            Vector512.Create(0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1)));
    }
}

Expected

<7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5>

Actual

<5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5>

Notes

Repros under DOTNET_TieredCompilation=0; DOTNET_JitMinOpts=1 prints the expected value.
MultiplyWideningAndAddSaturate behaves the same way.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions