-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
optComputeLoopSideEffects
to account for HWI stores (#61911)
Otherwise we can end up not seeing the loop has memory havoc. Also added an assert that will prevent this issue from arising in the future.
- Loading branch information
1 parent
d9a5789
commit 6069861
Showing
3 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.CompilerServices; | ||
using System.Runtime.Intrinsics; | ||
using System.Runtime.Intrinsics.X86; | ||
using System.Runtime.Intrinsics.Arm; | ||
|
||
unsafe class LoopSideEffectsForHwiStores | ||
{ | ||
public static int Main() | ||
{ | ||
static bool VerifyExpectedVtor(Vector128<int> a) => a.Equals(Vector128.Create(4)); | ||
|
||
var a = new ClassWithVtor(); | ||
|
||
fixed (Vector128<int>* p = &a.VtorField) | ||
{ | ||
if (Sse2.IsSupported && !VerifyExpectedVtor(ProblemWithSse2(a, (byte*)p))) | ||
{ | ||
System.Console.WriteLine("ProblemWithSse2 failed!"); | ||
return 101; | ||
} | ||
|
||
if (AdvSimd.IsSupported && !VerifyExpectedVtor(ProblemWithAdvSimd(a, (byte*)p))) | ||
{ | ||
System.Console.WriteLine("ProblemWithAdvSimd failed!"); | ||
return 101; | ||
} | ||
} | ||
|
||
return 100; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static unsafe Vector128<int> ProblemWithSse2(ClassWithVtor a, byte* p) | ||
{ | ||
Vector128<int> vtor = Vector128<int>.Zero; | ||
|
||
a.VtorField = Vector128.Create(1); | ||
a.VtorField = Sse2.Add(a.VtorField, a.VtorField); | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
vtor = Sse2.Add(vtor, Sse2.Add(a.VtorField, a.VtorField)); | ||
Sse2.Store(p, Vector128<byte>.Zero); | ||
} | ||
|
||
return vtor; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static unsafe Vector128<int> ProblemWithAdvSimd(ClassWithVtor a, byte* p) | ||
{ | ||
Vector128<int> vtor = Vector128<int>.Zero; | ||
|
||
a.VtorField = Vector128.Create(1); | ||
a.VtorField = AdvSimd.Add(a.VtorField, a.VtorField); | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
vtor = AdvSimd.Add(vtor, AdvSimd.Add(a.VtorField, a.VtorField)); | ||
AdvSimd.Store(p, Vector128<byte>.Zero); | ||
} | ||
|
||
return vtor; | ||
} | ||
|
||
class ClassWithVtor | ||
{ | ||
public Vector128<int> VtorField; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/tests/JIT/opt/Loops/LoopSideEffectsForHwiStores.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<CLRTestPriority>1</CLRTestPriority> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DebugType>PdbOnly</DebugType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |