-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Optimize box + isinst + unbox.any as nop
#1817
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 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b85d02a
Optimize `box + isinst + unbox.any` as `nop`
EgorBo 017eb8c
Formatting
EgorBo 8eb9f80
Address feedback
EgorBo ffdc2e1
Add tests
EgorBo 8c80114
Fix CI errors
EgorBo 3cf7d5c
Address feedback
EgorBo 6d586f4
Merge branch 'master' of github.com:dotnet/runtime into opt-pm-boxing
EgorBo 9b6726f
Address feedback
EgorBo 4e36642
Remove box_isinst_unbox-noinline.csproj
EgorBo 8040f7d
Fix Formatting
EgorBo 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
20 changes: 20 additions & 0 deletions
20
src/coreclr/tests/src/JIT/Generics/Conversions/Boxing/box_isinst_unbox-noinline.csproj
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,20 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <DebugType>None</DebugType> | ||
| <Optimize>True</Optimize> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="box_isinst_unbox.cs" /> | ||
| </ItemGroup> | ||
| <PropertyGroup> | ||
| <CLRTestBatchPreCommands><![CDATA[ | ||
EgorBo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $(CLRTestBatchPreCommands) | ||
| set COMPlus_JitNoInline=1 | ||
| ]]></CLRTestBatchPreCommands> | ||
| <BashCLRTestPreCommands><![CDATA[ | ||
| $(BashCLRTestPreCommands) | ||
| export COMPlus_JitNoInline=1 | ||
| ]]></BashCLRTestPreCommands> | ||
| </PropertyGroup> | ||
| </Project> | ||
237 changes: 237 additions & 0 deletions
237
src/coreclr/tests/src/JIT/Generics/Conversions/Boxing/box_isinst_unbox.cs
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,237 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| public static class Tests | ||
| { | ||
| private static int returnCode = 100; | ||
|
|
||
| public static int BoxIsInstUnbox1<T>(T t) => t is int n ? n : -1; | ||
| public static int BoxIsInstUnbox2<T>(T t) => t is string n ? n.Length : -1; | ||
| public static int BoxIsInstUnbox3<T>(T t) => t is Struct1<int> n ? n.a : -1; | ||
| public static int BoxIsInstUnbox4<T>(T t) => t is Struct1<IDisposable> n ? n.GetHashCode() : -1; | ||
| public static int BoxIsInstUnbox5<T>(T t) => t is Class1<int> n ? n.a : -1; | ||
| public static int BoxIsInstUnbox6<T>(T t) => t is RefBase n ? n.a : -1; | ||
| public static int BoxIsInstUnbox7<T>(T t) => t is object[] n ? n.Length : -1; | ||
|
|
||
| public static void Expect(this int actual, int expected, [CallerLineNumber] int line = 0) | ||
| { | ||
| if (expected != actual) | ||
| { | ||
| Console.WriteLine($"{actual} != {expected}, line {line}."); | ||
| returnCode++; | ||
| } | ||
| } | ||
|
|
||
| public static int Main() | ||
| { | ||
| BoxIsInstUnbox1<int>(1).Expect(1); | ||
| BoxIsInstUnbox1<uint>(1).Expect(-1); | ||
| BoxIsInstUnbox1<byte>(1).Expect(-1); | ||
| BoxIsInstUnbox1<long>(1).Expect(-1); | ||
| BoxIsInstUnbox1<decimal>(1).Expect(-1); | ||
| BoxIsInstUnbox1<int?>(1).Expect(1); | ||
| BoxIsInstUnbox1<int?>(null).Expect(-1); | ||
| BoxIsInstUnbox1<uint?>(1).Expect(-1); | ||
| BoxIsInstUnbox1<string>("1").Expect(-1); | ||
| BoxIsInstUnbox1<string>(1.ToString()).Expect(-1); | ||
| BoxIsInstUnbox1<string>(null).Expect(-1); | ||
| BoxIsInstUnbox1<Struct1<int>>(new Struct1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox1<Struct1<int>?>(new Struct1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox1<Struct1<uint>>(new Struct1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox1<Struct2<IDisposable>>(new Struct2<IDisposable>()).Expect(-1); | ||
| BoxIsInstUnbox1<Class1<int>>(new Class1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox1<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox1<Class1<string>>(new Class1<string> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox1<Class1<int>>(new Class1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox1<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox1<Class1<string>>(new Class1<string> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox1<Class1<IDisposable>>(new Class1<IDisposable> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox1<string[]>(new string[1]).Expect(-1); | ||
| BoxIsInstUnbox1<object[]>(new string[1]).Expect(-1); | ||
| BoxIsInstUnbox1<IEnumerable<object>>(new string[1]).Expect(-1); | ||
|
|
||
| BoxIsInstUnbox2<int>(1).Expect(-1); | ||
| BoxIsInstUnbox2<uint>(1).Expect(-1); | ||
| BoxIsInstUnbox2<byte>(1).Expect(-1); | ||
| BoxIsInstUnbox2<long>(1).Expect(-1); | ||
| BoxIsInstUnbox2<decimal>(1).Expect(-1); | ||
| BoxIsInstUnbox2<int?>(1).Expect(-1); | ||
| BoxIsInstUnbox2<int?>(null).Expect(-1); | ||
| BoxIsInstUnbox2<uint?>(1).Expect(-1); | ||
| BoxIsInstUnbox2<string>("1").Expect(1); | ||
| BoxIsInstUnbox2<string>(1.ToString()).Expect(1); | ||
| BoxIsInstUnbox2<string>(null).Expect(-1); | ||
| BoxIsInstUnbox2<Struct1<int>>(new Struct1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox2<Struct1<int>?>(new Struct1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox2<Struct1<uint>>(new Struct1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox2<Struct2<IDisposable>>(new Struct2<IDisposable>()).Expect(-1); | ||
| BoxIsInstUnbox2<Class1<int>>(new Class1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox2<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox2<Class1<string>>(new Class1<string> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox2<Class1<int>>(new Class1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox2<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox2<Class1<string>>(new Class1<string> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox2<Class1<IDisposable>>(new Class1<IDisposable> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox2<string[]>(new string[1]).Expect(-1); | ||
| BoxIsInstUnbox2<object[]>(new string[1]).Expect(-1); | ||
| BoxIsInstUnbox2<IEnumerable<object>>(new string[1]).Expect(-1); | ||
|
|
||
| BoxIsInstUnbox3<int>(1).Expect(-1); | ||
| BoxIsInstUnbox3<uint>(1).Expect(-1); | ||
| BoxIsInstUnbox3<byte>(1).Expect(-1); | ||
| BoxIsInstUnbox3<long>(1).Expect(-1); | ||
| BoxIsInstUnbox3<decimal>(1).Expect(-1); | ||
| BoxIsInstUnbox3<int?>(1).Expect(-1); | ||
| BoxIsInstUnbox3<int?>(null).Expect(-1); | ||
| BoxIsInstUnbox3<uint?>(1).Expect(-1); | ||
| BoxIsInstUnbox3<string>("1").Expect(-1); | ||
| BoxIsInstUnbox3<string>(1.ToString()).Expect(-1); | ||
| BoxIsInstUnbox3<string>(null).Expect(-1); | ||
| BoxIsInstUnbox3<Struct1<int>>(new Struct1<int> { a = 1 }).Expect(1); | ||
| BoxIsInstUnbox3<Struct1<int>?>(new Struct1<int> { a = 1 }).Expect(1); | ||
| BoxIsInstUnbox3<Struct1<uint>>(new Struct1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox3<Struct2<IDisposable>>(new Struct2<IDisposable>()).Expect(-1); | ||
| BoxIsInstUnbox3<Class1<int>>(new Class1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox3<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox3<Class1<string>>(new Class1<string> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox3<Class1<int>>(new Class1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox3<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox3<Class1<string>>(new Class1<string> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox3<Class1<IDisposable>>(new Class1<IDisposable> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox3<string[]>(new string[1]).Expect(-1); | ||
| BoxIsInstUnbox3<object[]>(new string[1]).Expect(-1); | ||
| BoxIsInstUnbox3<IEnumerable<object>>(new string[1]).Expect(-1); | ||
|
|
||
| BoxIsInstUnbox4<int>(1).Expect(-1); | ||
| BoxIsInstUnbox4<uint>(1).Expect(-1); | ||
| BoxIsInstUnbox4<byte>(1).Expect(-1); | ||
| BoxIsInstUnbox4<long>(1).Expect(-1); | ||
| BoxIsInstUnbox4<decimal>(1).Expect(-1); | ||
| BoxIsInstUnbox4<int?>(1).Expect(-1); | ||
| BoxIsInstUnbox4<int?>(null).Expect(-1); | ||
| BoxIsInstUnbox4<uint?>(1).Expect(-1); | ||
| BoxIsInstUnbox4<string>("1").Expect(-1); | ||
| BoxIsInstUnbox4<string>(1.ToString()).Expect(-1); | ||
| BoxIsInstUnbox4<string>(null).Expect(-1); | ||
| BoxIsInstUnbox4<Struct1<int>>(new Struct1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox4<Struct1<int>?>(new Struct1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox4<Struct1<uint>>(new Struct1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox4<Struct2<IDisposable>>(new Struct2<IDisposable>()).Expect(-1); | ||
| BoxIsInstUnbox4<Class1<int>>(new Class1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox4<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox4<Class1<string>>(new Class1<string> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox4<Class1<int>>(new Class1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox4<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox4<Class1<string>>(new Class1<string> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox4<Class1<IDisposable>>(new Class1<IDisposable> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox4<string[]>(new string[1]).Expect(-1); | ||
| BoxIsInstUnbox4<object[]>(new string[1]).Expect(-1); | ||
| BoxIsInstUnbox4<IEnumerable<object>>(new string[1]).Expect(-1); | ||
|
|
||
| BoxIsInstUnbox5<int>(1).Expect(-1); | ||
| BoxIsInstUnbox5<uint>(1).Expect(-1); | ||
| BoxIsInstUnbox5<byte>(1).Expect(-1); | ||
| BoxIsInstUnbox5<long>(1).Expect(-1); | ||
| BoxIsInstUnbox5<decimal>(1).Expect(-1); | ||
| BoxIsInstUnbox5<int?>(1).Expect(-1); | ||
| BoxIsInstUnbox5<int?>(null).Expect(-1); | ||
| BoxIsInstUnbox5<uint?>(1).Expect(-1); | ||
| BoxIsInstUnbox5<string>("1").Expect(-1); | ||
| BoxIsInstUnbox5<string>(1.ToString()).Expect(-1); | ||
| BoxIsInstUnbox5<string>(null).Expect(-1); | ||
| BoxIsInstUnbox5<Struct1<int>>(new Struct1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox5<Struct1<int>?>(new Struct1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox5<Struct1<uint>>(new Struct1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox5<Struct2<IDisposable>>(new Struct2<IDisposable>()).Expect(-1); | ||
| BoxIsInstUnbox5<Class1<int>>(new Class1<int> { a = 1 }).Expect(1); | ||
| BoxIsInstUnbox5<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox5<Class1<string>>(new Class1<string> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox5<Class1<int>>(new Class1<int> { a = 1 }).Expect(1); | ||
| BoxIsInstUnbox5<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox5<Class1<string>>(new Class1<string> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox5<Class1<IDisposable>>(new Class1<IDisposable> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox5<string[]>(new string[1]).Expect(-1); | ||
| BoxIsInstUnbox5<object[]>(new string[1]).Expect(-1); | ||
| BoxIsInstUnbox5<IEnumerable<object>>(new string[1]).Expect(-1); | ||
|
|
||
| BoxIsInstUnbox6<int>(1).Expect(-1); | ||
| BoxIsInstUnbox6<uint>(1).Expect(-1); | ||
| BoxIsInstUnbox6<byte>(1).Expect(-1); | ||
| BoxIsInstUnbox6<long>(1).Expect(-1); | ||
| BoxIsInstUnbox6<decimal>(1).Expect(-1); | ||
| BoxIsInstUnbox6<int?>(1).Expect(-1); | ||
| BoxIsInstUnbox6<int?>(null).Expect(-1); | ||
| BoxIsInstUnbox6<uint?>(1).Expect(-1); | ||
| BoxIsInstUnbox6<string>("1").Expect(-1); | ||
| BoxIsInstUnbox6<string>(1.ToString()).Expect(-1); | ||
| BoxIsInstUnbox6<string>(null).Expect(-1); | ||
| BoxIsInstUnbox6<Struct1<int>>(new Struct1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox6<Struct1<int>?>(new Struct1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox6<Struct1<uint>>(new Struct1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox6<Struct2<IDisposable>>(new Struct2<IDisposable>()).Expect(-1); | ||
| BoxIsInstUnbox6<Class1<int>>(new Class1<int> { a = 1 }).Expect(1); | ||
| BoxIsInstUnbox6<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(1); | ||
| BoxIsInstUnbox6<Class1<string>>(new Class1<string> { a = 1 }).Expect(1); | ||
| BoxIsInstUnbox6<Class1<int>>(new Class1<int> { a = 1 }).Expect(1); | ||
| BoxIsInstUnbox6<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(1); | ||
| BoxIsInstUnbox6<Class1<string>>(new Class1<string> { a = 1 }).Expect(1); | ||
| BoxIsInstUnbox6<Class1<IDisposable>>(new Class1<IDisposable> { a = 1 }).Expect(1); | ||
| BoxIsInstUnbox6<string[]>(new string[1]).Expect(-1); | ||
| BoxIsInstUnbox6<object[]>(new string[1]).Expect(-1); | ||
| BoxIsInstUnbox6<IEnumerable<object>>(new string[1]).Expect(-1); | ||
|
|
||
| BoxIsInstUnbox7<int>(1).Expect(-1); | ||
| BoxIsInstUnbox7<uint>(1).Expect(-1); | ||
| BoxIsInstUnbox7<byte>(1).Expect(-1); | ||
| BoxIsInstUnbox7<long>(1).Expect(-1); | ||
| BoxIsInstUnbox7<decimal>(1).Expect(-1); | ||
| BoxIsInstUnbox7<int?>(1).Expect(-1); | ||
| BoxIsInstUnbox7<int?>(null).Expect(-1); | ||
| BoxIsInstUnbox7<uint?>(1).Expect(-1); | ||
| BoxIsInstUnbox7<string>("1").Expect(-1); | ||
| BoxIsInstUnbox7<string>(1.ToString()).Expect(-1); | ||
| BoxIsInstUnbox7<string>(null).Expect(-1); | ||
| BoxIsInstUnbox7<Struct1<int>>(new Struct1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox7<Struct1<int>?>(new Struct1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox7<Struct1<uint>>(new Struct1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox7<Struct2<IDisposable>>(new Struct2<IDisposable>()).Expect(-1); | ||
| BoxIsInstUnbox7<Class1<int>>(new Class1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox7<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox7<Class1<string>>(new Class1<string> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox7<Class1<int>>(new Class1<int> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox7<Class1<uint>>(new Class1<uint> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox7<Class1<string>>(new Class1<string> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox7<Class1<IDisposable>>(new Class1<IDisposable> { a = 1 }).Expect(-1); | ||
| BoxIsInstUnbox7<string[]>(new string[1]).Expect(1); | ||
| BoxIsInstUnbox7<object[]>(new string[1]).Expect(1); | ||
| BoxIsInstUnbox7<IEnumerable<object>>(new string[1]).Expect(1); | ||
|
|
||
| return returnCode; | ||
| } | ||
| } | ||
|
|
||
| public struct Struct1<T> | ||
| { | ||
| public T a; | ||
| } | ||
|
|
||
| public struct Struct2<T> | ||
| { | ||
| public T a; | ||
| } | ||
|
|
||
| public class RefBase : IDisposable | ||
| { | ||
| public int a; | ||
| public void Dispose() { } | ||
| } | ||
|
|
||
| public class Class1<T> : RefBase | ||
| { | ||
| public T b; | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/coreclr/tests/src/JIT/Generics/Conversions/Boxing/box_isinst_unbox.csproj
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,10 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <DebugType>None</DebugType> | ||
| <Optimize>True</Optimize> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="box_isinst_unbox.cs" /> | ||
| </ItemGroup> | ||
| </Project> |
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.
Uh oh!
There was an error while loading. Please reload this page.