-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
The problem was described in https://github.com/dotnet/coreclr/issues/19888#issuecomment-423769762 and results from code quality question asked by @gdkchan https://github.com/dotnet/coreclr/issues/19888#issuecomment-423766095.
The code taken from OP illustrating problem is as follows:
private static void Test()
{
Vector128<float> vec = Sse.SetZeroVector128();
vec = VectorInsertSingle(vec, 0, 1.0f);
vec = VectorInsertSingle(vec, 1, 1.5f);
vec = VectorInsertSingle(vec, 2, 2.0f);
vec = VectorInsertSingle(vec, 3, 2.5f);
}
public static Vector128<float> VectorInsertSingle(Vector128<float> vector, byte index, float value)
{
//Produces sub-optimal code (jump table fallback,
//JIT doesn't notice that the value is constant after inline).
return Sse41.Insert(vector, value, (byte)(index << 4));
}Method VectorInsertSingle is inlined into method Test what should result in folding index into const value passed as a parameter. Currently Jit does not handle two constructs: (i) immediate HW intrinsic expansion after/during inlining, (ii) const expression folding. The second problem is covered by #11062 and this issue is created to track the first problem.
One of the possible solutions is covered by dotnet/csharplang#886 proposal.
category:cq
theme:hardware-intrinsics
skill-level:intermediate
cost:medium