diff options
author | Andy Ayers <andya@microsoft.com> | 2018-03-20 08:36:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-20 08:36:14 -0700 |
commit | a3e9b7ff25a31baa41db2df4c3a164aa4882b88c (patch) | |
tree | 3b5d34a346e4e359316e99b4968ba3375d17b2e4 /tests | |
parent | dfd1f1caa5685e968be2a845b5c0bc3ad17390dc (diff) | |
download | coreclr-a3e9b7ff25a31baa41db2df4c3a164aa4882b88c.tar.gz coreclr-a3e9b7ff25a31baa41db2df4c3a164aa4882b88c.tar.bz2 coreclr-a3e9b7ff25a31baa41db2df4c3a164aa4882b88c.zip |
JIT: remove boxing for interface call to shared generic struct (#17006)
Improve the jit's ability to optimize a box-interface call sequence
to handle cases where the unboxed entry point requires a method table
argument.
Added two test cases, one from the inspiring issue, and another where
the jit is then able to inline the method.
Closes #16982.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/JIT/opt/Devirtualization/box1.cs | 29 | ||||
-rw-r--r-- | tests/src/JIT/opt/Devirtualization/box1.csproj | 34 | ||||
-rw-r--r-- | tests/src/JIT/opt/Devirtualization/box2.cs | 24 | ||||
-rw-r--r-- | tests/src/JIT/opt/Devirtualization/box2.csproj | 35 |
4 files changed, 122 insertions, 0 deletions
diff --git a/tests/src/JIT/opt/Devirtualization/box1.cs b/tests/src/JIT/opt/Devirtualization/box1.cs new file mode 100644 index 0000000000..51121f37d8 --- /dev/null +++ b/tests/src/JIT/opt/Devirtualization/box1.cs @@ -0,0 +1,29 @@ +// 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; + +interface IPrint +{ + void Print(); +} + +struct X<T> : IPrint +{ + public X(T t) { _t = t; } + public void Print() { Console.WriteLine(_t); } + T _t; +} + +class Y +{ + static int Main() + { + var s = new X<string>("hello, world!"); + // Jit should devirtualize, remove box, + // change to call unboxed entry, then inline. + ((IPrint)s).Print(); + return 100; + } +} diff --git a/tests/src/JIT/opt/Devirtualization/box1.csproj b/tests/src/JIT/opt/Devirtualization/box1.csproj new file mode 100644 index 0000000000..a1390b0c17 --- /dev/null +++ b/tests/src/JIT/opt/Devirtualization/box1.csproj @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>$(MSBuildProjectName)</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <PropertyGroup> + <DebugType>None</DebugType> + <Optimize>True</Optimize> + </PropertyGroup> + <ItemGroup> + <Compile Include="box1.cs" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> +</Project>
\ No newline at end of file diff --git a/tests/src/JIT/opt/Devirtualization/box2.cs b/tests/src/JIT/opt/Devirtualization/box2.cs new file mode 100644 index 0000000000..9e82ef2ff5 --- /dev/null +++ b/tests/src/JIT/opt/Devirtualization/box2.cs @@ -0,0 +1,24 @@ +// 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.Threading; +using System.Threading.Tasks; + +class Program +{ + static async Task<int> Main() + { + for (int i = 0; i < 10; i++) + { + // In the associated AwaitUnsafeOnCompleted, the + // jit should devirtualize, remove the box, + // and change to call unboxed entry, passing + // extra context argument. + await new ValueTask<string>(Task.Delay(1).ContinueWith(_ => default(string))).ConfigureAwait(false); + } + + return 100; + } +} diff --git a/tests/src/JIT/opt/Devirtualization/box2.csproj b/tests/src/JIT/opt/Devirtualization/box2.csproj new file mode 100644 index 0000000000..e821b3bca9 --- /dev/null +++ b/tests/src/JIT/opt/Devirtualization/box2.csproj @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>$(MSBuildProjectName)</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <PropertyGroup> + <Langversion>7.2</Langversion> + <DebugType>None</DebugType> + <Optimize>True</Optimize> + </PropertyGroup> + <ItemGroup> + <Compile Include="box2.cs" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> +</Project>
\ No newline at end of file |