JIT: (bug) AvxVnni.V512.MultiplyWideningAndAdd folded into BlendVariable loses the merge operand
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
### Minimal repro
```csharp
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 Test(Vector512 fallback, Vector512 addend,
Vector512 left, Vector512 right,
Vector512 a, Vector512 b)
{
Vector512 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.Zero,
Vector512.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.
Contributor guide
Assessment
This issue has not been assessed yet.