-
Notifications
You must be signed in to change notification settings - Fork 5.1k
JIT: teach VN to fold type comparisons #72136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
27fe171
JIT: teach VN to fold type comparisons
AndyAyersMS e4f8bcb
add test case
AndyAyersMS 31d16fa
handle function pointer case
AndyAyersMS 768915e
crossgen2 support
AndyAyersMS 0b63346
leave fnptrs broken for now
AndyAyersMS 0092cb5
map from embedded handle to compile time handle and fully evaluate VN
AndyAyersMS 19d5fce
tolerate missing compile time handle
AndyAyersMS b99df80
fix 32 bit builds
AndyAyersMS 0156b39
really fix 32 bit
AndyAyersMS d51c73a
add mono AOT excludes
AndyAyersMS a090629
minor TP refactor
AndyAyersMS b926330
restrict to unequal VNs, remove mono test exclusions
AndyAyersMS 0c8cb31
re-add mono exclusions
AndyAyersMS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,170 @@ | ||
// 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.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
|
||
public enum Enum1 : int { A } | ||
public enum Enum2 : uint { A } | ||
|
||
class TypeTestFolding | ||
{ | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static void SideEffect() { } | ||
|
||
//static bool True0() => typeof(delegate*<int, double>) == typeof(delegate* unmanaged<float, void*, void>); | ||
//static bool True1() | ||
//{ | ||
// var t0 = typeof(delegate*<int, double>); | ||
// SideEffect(); | ||
// var t1 = typeof(delegate* unmanaged<float, void*, void>); | ||
// return t0 == t1; | ||
//} | ||
|
||
static bool True2() => typeof(TypeTestFolding) == typeof(TypeTestFolding); | ||
static bool True3() | ||
{ | ||
var t0 = typeof(TypeTestFolding); | ||
SideEffect(); | ||
var t1 = typeof(TypeTestFolding); | ||
return t0 == t1; | ||
} | ||
|
||
static bool True4() => typeof(ValueTuple<TypeTestFolding>) == typeof(ValueTuple<TypeTestFolding>); | ||
static bool True5() | ||
{ | ||
var t0 = typeof(ValueTuple<TypeTestFolding>); | ||
SideEffect(); | ||
var t1 = typeof(ValueTuple<TypeTestFolding>); | ||
return t0 == t1; | ||
} | ||
|
||
//static bool True6() => typeof(delegate*<int>) == typeof(nint); | ||
//static bool True7() | ||
//{ | ||
// var t0 = typeof(delegate*<int>); | ||
// SideEffect(); | ||
// var t1 = typeof(nint); | ||
// return t0 == t1; | ||
//} | ||
|
||
static bool False0() => typeof(List<object>) == typeof(List<string>); | ||
static bool False1() | ||
{ | ||
var t0 = typeof(List<object>); | ||
SideEffect(); | ||
var t1 = typeof(List<string>); | ||
return t0 == t1; | ||
} | ||
|
||
static bool False2() => typeof(int) == typeof(Enum1); | ||
static bool False3() | ||
{ | ||
var t0 = typeof(int); | ||
SideEffect(); | ||
var t1 = typeof(Enum1); | ||
return t0 == t1; | ||
} | ||
|
||
static bool False4() => typeof(Enum1) == typeof(Enum2); | ||
static bool False5() | ||
{ | ||
var t0 = typeof(Enum1); | ||
SideEffect(); | ||
var t1 = typeof(Enum2); | ||
return t0 == t1; | ||
} | ||
|
||
static bool False6() => typeof(int?) == typeof(uint?); | ||
static bool False7() | ||
{ | ||
var t0 = typeof(int?); | ||
SideEffect(); | ||
var t1 = typeof(uint?); | ||
return t0 == t1; | ||
} | ||
|
||
static bool False8() => typeof(int?) == typeof(Enum1?); | ||
static bool False9() | ||
{ | ||
var t0 = typeof(int?); | ||
SideEffect(); | ||
var t1 = typeof(Enum1?); | ||
return t0 == t1; | ||
} | ||
|
||
static bool False10() => typeof(ValueTuple<TypeTestFolding>) == typeof(ValueTuple<string>); | ||
static bool False11() | ||
{ | ||
var t0 = typeof(ValueTuple<TypeTestFolding>); | ||
SideEffect(); | ||
var t1 = typeof(ValueTuple<string>); | ||
return t0 == t1; | ||
} | ||
|
||
//static bool False12() => typeof(delegate*<int>[]) == typeof(delegate*<float>[]); | ||
//static bool False13() | ||
//{ | ||
// var t0 = typeof(delegate*<int>[]); | ||
// SideEffect(); | ||
// var t1 = typeof(delegate*<float>[]); | ||
// return t0 == t1; | ||
//} | ||
|
||
static bool False14() => typeof(int[]) == typeof(uint[]); | ||
static bool False15() | ||
{ | ||
var t0 = typeof(int[]); | ||
SideEffect(); | ||
var t1 = typeof(uint[]); | ||
return t0 == t1; | ||
} | ||
|
||
//static bool False16() => typeof(delegate*<int>) == typeof(IntPtr); | ||
//static bool False17() | ||
//{ | ||
// var t0 = typeof(delegate*<int>); | ||
// SideEffect(); | ||
// var t1 = typeof(UIntPtr); | ||
// return t0 == t1; | ||
//} | ||
|
||
unsafe static int Main() | ||
{ | ||
delegate*<bool>[] trueFuncs = new delegate*<bool>[] { &True2, &True3, &True4, &True5 }; | ||
delegate*<bool>[] falseFuncs = new delegate*<bool>[] { &False0, &False1, &False2, &False3, &False4, &False5, | ||
&False6, &False7, &False8, &False9, &False10, &False11, | ||
&False14, &False15 }; | ||
|
||
int result = 100; | ||
int trueCount = 0; | ||
int falseCount = 0; | ||
|
||
foreach (var tf in trueFuncs) | ||
{ | ||
if (!tf()) | ||
{ | ||
Console.WriteLine($"True{trueCount} failed"); | ||
result++; | ||
} | ||
trueCount++; | ||
} | ||
|
||
foreach (var ff in falseFuncs) | ||
{ | ||
if (ff()) | ||
{ | ||
Console.WriteLine($"False{falseCount} failed"); | ||
result++; | ||
} | ||
falseCount++; | ||
} | ||
|
||
Console.WriteLine($"Ran {trueCount + falseCount} tests; result {result}"); | ||
return result; | ||
} | ||
} | ||
|
||
|
||
|
This file contains hidden or 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> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DebugType>None</DebugType> | ||
<Optimize>True</Optimize> | ||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this function is injective, e.g. all function pointers map to
typeof(IntPtr)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we should check with the runtime via
compareTypesForEquality
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth to note that all function pointer typeofs currently compare as equal.