Create<int>(ToScalar(Dot<short>(...))) is folded into the Dot<short> vector even though the element types differ, so the sum is replicated per 16-bit lane.
Minimal Repro
using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
public class Program
{
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
static Vector128<int> Test(Vector128<short> a, Vector128<short> b) => Vector128.Create((int)Vector128.Dot(a, b));
public static void Main()
{
Vector128<short> v = Vector128.Create((short)1);
Console.WriteLine(Test(v, v));
}
}
Expected
Actual
<524296, 524296, 524296, 524296>
Regression?
Not a regression. Reproduces on .NET 8, 9, 10, 11 RC2 and main (win-x64).
Notes
In fgOptimizeHWIntrinsic, the NI_Vector_Create case only checks hwop1->TypeGet() == retType (the vector size), not the SIMD base type.
Create<int>(ToScalar(Dot<short>(...)))is folded into theDot<short>vector even though the element types differ, so the sum is replicated per 16-bit lane.Minimal Repro
Expected
Actual
Regression?
Not a regression. Reproduces on .NET 8, 9, 10, 11 RC2 and main (win-x64).
Notes
In
fgOptimizeHWIntrinsic, theNI_Vector_Createcase only checkshwop1->TypeGet() == retType(the vector size), not the SIMD base type.