Skip to content

Commit cc59b89

Browse files
Ensure that the Create(Dot(...)) optimization doesn't kick in for Vector2 pre SSE4.1 (#96951)
* Ensure that the Create(Dot(...)) optimization doesn't kick in for Vector2 pre SSE4.1 * Make sure to use #if defined(...) * Add missing using * Fix a type in the test
1 parent 1263107 commit cc59b89

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/coreclr/jit/morph.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10605,6 +10605,16 @@ GenTree* Compiler::fgOptimizeHWIntrinsic(GenTreeHWIntrinsic* node)
1060510605
break;
1060610606
}
1060710607

10608+
#if defined(TARGET_XARCH)
10609+
if ((node->GetSimdSize() == 8) && !compOpportunisticallyDependsOn(InstructionSet_SSE41))
10610+
{
10611+
// When SSE4.1 isn't supported then Vector2 only needs a single horizontal add
10612+
// which means the result isn't broadcast across the entire vector and we can't
10613+
// optimize
10614+
break;
10615+
}
10616+
#endif // TARGET_XARCH
10617+
1060810618
GenTree* op1 = node->Op(1);
1060910619
GenTree* sqrt = nullptr;
1061010620
GenTree* toScalar = nullptr;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Numerics;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.Intrinsics;
8+
using Xunit;
9+
10+
public static class Runtime_96939
11+
{
12+
[Fact]
13+
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
14+
public static void Problem()
15+
{
16+
Assert.Equal(new Vector2(13), TestVector2(new Vector2(2, 3)));
17+
Assert.Equal(new Vector3(29), TestVector3(new Vector3(2, 3, 4)));
18+
Assert.Equal(new Vector4(54), TestVector4(new Vector4(2, 3, 4, 5)));
19+
}
20+
21+
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
22+
public static Vector2 TestVector2(Vector2 value)
23+
{
24+
return Vector2.Dot(value, value) * new Vector2(1, 1);
25+
}
26+
27+
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
28+
public static Vector3 TestVector3(Vector3 value)
29+
{
30+
return Vector3.Dot(value, value) * new Vector3(1, 1, 1);
31+
}
32+
33+
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
34+
public static Vector4 TestVector4(Vector4 value)
35+
{
36+
return Vector4.Dot(value, value) * new Vector4(1, 1, 1, 1);
37+
}
38+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
<DebugType>None</DebugType>
5+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<Compile Include="$(MSBuildProjectName).cs" />
9+
</ItemGroup>
10+
</Project>

0 commit comments

Comments
 (0)