-
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.
JIT: redundant branch destructure dominating and/or
If a branch predicate `p` is dominated by another branch with predicate `AND(p, ..)` or `OR(p, ...)` we may be able to infer the value of `p`. This is useful on its own, and should help unblock #62689.
- Loading branch information
1 parent
2291ac9
commit 34e4c3f
Showing
5 changed files
with
419 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
149 changes: 149 additions & 0 deletions
149
src/tests/JIT/opt/RedundantBranch/RedundantBranchAnd.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,149 @@ | ||
// 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; | ||
|
||
class RedundantBranchAnd | ||
{ | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static int And_00(int a, int b) | ||
{ | ||
if ((a > 0) & (b > 0)) | ||
{ | ||
// redundant | ||
if (a > 0) | ||
{ | ||
return 1; | ||
} | ||
return -1; | ||
} | ||
return 3; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static int And_01(int a, int b) | ||
{ | ||
if ((a > 0) & (b > 0)) | ||
{ | ||
// redundant | ||
if (a <= 0) | ||
{ | ||
return -1; | ||
} | ||
return 1; | ||
} | ||
return 3; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static int And_02(int a, int b) | ||
{ | ||
if ((a > 0) & (b > 0)) | ||
{ | ||
// redundant | ||
if (b > 0) | ||
{ | ||
return 1; | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
return 3; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static int And_03(int a, int b) | ||
{ | ||
if ((a > 0) & (b > 0)) | ||
{ | ||
// redundant | ||
if (b <= 0) | ||
{ | ||
return -1; | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
return 3; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static int And_04(int a, int b) | ||
{ | ||
if ((a > 0) & (b > 0)) | ||
{ | ||
// redundant | ||
if ((a > 0) & (b > 0)) | ||
{ | ||
return 1; | ||
} | ||
return -1; | ||
} | ||
return 3; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static int And_05(int a, int b) | ||
{ | ||
if ((a == 0) & (b > 0)) | ||
{ | ||
// redundant | ||
if (a == 0) | ||
{ | ||
return 1; | ||
} | ||
return -1; | ||
} | ||
return 3; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static int And_06(int a, int b) | ||
{ | ||
if ((a == 0) & (b > 0)) | ||
{ | ||
// redundant | ||
if (b > 0) | ||
{ | ||
return 1; | ||
} | ||
return -1; | ||
} | ||
return 3; | ||
} | ||
|
||
|
||
public static int Main() | ||
{ | ||
Func<int, int, int>[] funcs = {And_00, And_01, And_02, And_03, And_04, And_05, And_06}; | ||
int funcNum = 0; | ||
int cases = 0; | ||
int errors= 0; | ||
|
||
foreach (var f in funcs) | ||
{ | ||
for (int a = -1; a <= 1; a++) | ||
{ | ||
for (int b = -1; b <= 1; b++) | ||
{ | ||
cases++; | ||
int result = f(a, b); | ||
|
||
if (result < 0) | ||
{ | ||
Console.WriteLine($"And_0{funcNum}({a},{b}) = {result} wrong\n"); | ||
errors++; | ||
} | ||
} | ||
} | ||
|
||
funcNum++; | ||
} | ||
|
||
Console.WriteLine($"{cases} tests, {errors} errors"); | ||
return errors > 0 ? -1 : 100; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/tests/JIT/opt/RedundantBranch/RedundantBranchAnd.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,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<DebugType /> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.