Skip to content

Commit

Permalink
Added a test verifying that double negation is not removed for CSEs
Browse files Browse the repository at this point in the history
  • Loading branch information
SingleAccretion committed Mar 29, 2021
1 parent 16052be commit b413465
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/tests/JIT/opt/CSE/CSEWithDoubleNegation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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;

namespace CSEWithDoubleNegation
{
class DoNotMorphAwayCSEThatRepresentsDoubleNegation
{
private static int _static = 0;

static int Main(string[] args)
{
if (DoubleNeg() != 22)
{
Console.WriteLine("DoubleNeg() failed to return the expected value of 22");
return -1;
}

return 100;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static int DoubleNeg()
{
var a = 21;
_static = 42;

return 43 - (0 - (a - _static));
}
}
}

13 changes: 13 additions & 0 deletions src/tests/JIT/opt/CSE/CSEWithDoubleNegation.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestPriority>1</CLRTestPriority>
</PropertyGroup>
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="CSEWithDoubleNegation.cs" />
</ItemGroup>
</Project>

0 comments on commit b413465

Please sign in to comment.