diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 3deada8eec085b..b20cd585882b87 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -10724,6 +10724,16 @@ GenTree* Compiler::fgOptimizeHWIntrinsic(GenTreeHWIntrinsic* node) break; } +#if defined(TARGET_XARCH) + if ((node->GetSimdSize() == 8) && !compOpportunisticallyDependsOn(InstructionSet_SSE41)) + { + // When SSE4.1 isn't supported then Vector2 only needs a single horizontal add + // which means the result isn't broadcast across the entire vector and we can't + // optimize + break; + } +#endif // TARGET_XARCH + GenTree* op1 = node->Op(1); GenTree* sqrt = nullptr; GenTree* toScalar = nullptr; diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_96939/Runtime_96939.cs b/src/tests/JIT/Regression/JitBlue/Runtime_96939/Runtime_96939.cs new file mode 100644 index 00000000000000..ac26af680eea80 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_96939/Runtime_96939.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.Intrinsics; +using Xunit; + +public static class Runtime_96939 +{ + [Fact] + [MethodImpl(MethodImplOptions.AggressiveOptimization)] + public static void Problem() + { + Assert.Equal(new Vector2(13), TestVector2(new Vector2(2, 3))); + Assert.Equal(new Vector3(29), TestVector3(new Vector3(2, 3, 4))); + Assert.Equal(new Vector4(54), TestVector4(new Vector4(2, 3, 4, 5))); + } + + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] + public static Vector2 TestVector2(Vector2 value) + { + return Vector2.Dot(value, value) * new Vector2(1, 1); + } + + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] + public static Vector3 TestVector3(Vector3 value) + { + return Vector3.Dot(value, value) * new Vector3(1, 1, 1); + } + + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] + public static Vector4 TestVector4(Vector4 value) + { + return Vector4.Dot(value, value) * new Vector4(1, 1, 1, 1); + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_96939/Runtime_96939.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_96939/Runtime_96939.csproj new file mode 100644 index 00000000000000..596f2374a8fb3b --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_96939/Runtime_96939.csproj @@ -0,0 +1,10 @@ + + + True + None + true + + + + +