-
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.
Account for global stores in hoisting properly (#67213)
* Take HWI stores into account in hoisting * Also fix ordinary stores while we're at it The contract for whether the LHS of a global ASG(IND, ...) should be marked with GLOB_REF is not clearly specified. * Add tests
- Loading branch information
1 parent
e402d8e
commit 7f94e6e
Showing
3 changed files
with
95 additions
and
12 deletions.
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,66 @@ | ||
// 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.Runtime.CompilerServices; | ||
using System.Runtime.Intrinsics; | ||
using System.Runtime.Intrinsics.X86; | ||
using System.Runtime.Intrinsics.Arm; | ||
|
||
unsafe class Hoisting | ||
{ | ||
public static int Main() | ||
{ | ||
var p = stackalloc int[4]; | ||
p[0] = 1; | ||
try | ||
{ | ||
ProblemWithHwiStore(p, -1); | ||
return 101; | ||
} | ||
catch (OverflowException) | ||
{ | ||
if (p[0] != 0) | ||
{ | ||
return 102; | ||
} | ||
} | ||
|
||
try | ||
{ | ||
ProblemWithNormalStore(p, -1); | ||
return 103; | ||
} | ||
catch (OverflowException) | ||
{ | ||
if (p[0] != -1) | ||
{ | ||
return 104; | ||
} | ||
} | ||
|
||
return 100; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static void ProblemWithHwiStore(int* p, int b) | ||
{ | ||
// Make sure we don't hoist the checked cast. | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
Vector128.Store(Vector128<int>.Zero, p); | ||
*p = (int)checked((uint)b); | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static void ProblemWithNormalStore(int* p, int b) | ||
{ | ||
// Make sure we don't hoist the checked cast. | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
*p = b; | ||
*p = (int)checked((uint)b); | ||
} | ||
} | ||
} |
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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DebugType>PdbOnly</DebugType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |