-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix morph negation transforms (#55145)
* Add a test * Fix the SUB(NEG(a), (NEG(b)) => SUB(b, a) case Also relax the condition for SUB(a, (NEG(b)) => ADD(a, b). * Fix the ADD((NEG(a), b) => SUB(b, a) case Also relax the condition for ADD(a, (NEG(b)) => SUB(a, b).
- Loading branch information
1 parent
7fed263
commit 5065d3b
Showing
3 changed files
with
60 additions
and
7 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
43 changes: 43 additions & 0 deletions
43
src/tests/JIT/Regression/JitBlue/Runtime_55140/Runtime_55140.cs
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,43 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
public class Runtime_55140 | ||
{ | ||
private static int _value; | ||
|
||
public static int Main() | ||
{ | ||
_value = 100; | ||
if (TestSubNegNeg() is not 1 and var subNegNeg) | ||
{ | ||
Console.WriteLine($"TestSubNegNeg returned: {subNegNeg}. Expected: 1"); | ||
return 101; | ||
} | ||
|
||
_value = 100; | ||
if (TestAddNeg() is not 1 and var addNeg) | ||
{ | ||
Console.WriteLine($"TestAddNeg returned: {addNeg}. Expected: 1"); | ||
return 102; | ||
} | ||
|
||
return 100; | ||
} | ||
|
||
// Test that the ADD(NEG(a), b) => SUB(b, a) transform does not reorder persistent side effects. | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static int TestAddNeg() | ||
{ | ||
return -Increment() + _value; | ||
} | ||
|
||
// Test that the SUB(NEG(a), NEG(b)) => SUB(b, a) transform does not reorder persistent side effects. | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static int TestSubNegNeg() | ||
{ | ||
return -Increment() - -_value; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static int Increment() => _value++; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/tests/JIT/Regression/JitBlue/Runtime_55140/Runtime_55140.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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DebugType>None</DebugType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |