summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Performance/CodeQuality/Inlining
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-12-27 16:46:08 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-12-27 16:46:08 +0900
commitdb20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch)
treee5435159cd1bf0519276363a6fe1663d1721bed3 /tests/src/JIT/Performance/CodeQuality/Inlining
parent4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff)
downloadcoreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz
coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2
coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'tests/src/JIT/Performance/CodeQuality/Inlining')
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsByte.cs3
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsChar.cs3
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsDouble.cs3
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsFloat.cs3
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsInt.cs3
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsLong.cs3
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsSByte.cs3
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsShort.cs3
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsString.cs3
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsUInt.cs3
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsULong.cs3
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsUShort.cs3
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/InlineGCStruct.cs148
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/InlineGCStruct.csproj44
-rw-r--r--tests/src/JIT/Performance/CodeQuality/Inlining/NoThrowInline.cs5
15 files changed, 232 insertions, 1 deletions
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsByte.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsByte.cs
index 8271c40a43..3b28f87fe5 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsByte.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsByte.cs
@@ -13,6 +13,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class ConstantArgsByte
{
@@ -928,3 +930,4 @@ public static class ConstantArgsByte
return (result ? 100 : -1);
}
}
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsChar.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsChar.cs
index 0d1f9284ba..0cc4b9c558 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsChar.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsChar.cs
@@ -13,6 +13,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class ConstantArgsChar
{
@@ -928,3 +930,4 @@ public static class ConstantArgsChar
return (result ? 100 : -1);
}
}
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsDouble.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsDouble.cs
index 6c95d482d5..4bd5683f0c 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsDouble.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsDouble.cs
@@ -13,6 +13,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class ConstantArgsDouble
{
@@ -808,3 +810,4 @@ public static class ConstantArgsDouble
return (result ? 100 : -1);
}
}
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsFloat.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsFloat.cs
index bbd65a4004..f609a4bb44 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsFloat.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsFloat.cs
@@ -13,6 +13,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class ConstantArgsFloat
{
@@ -808,3 +810,4 @@ public static class ConstantArgsFloat
return (result ? 100 : -1);
}
}
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsInt.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsInt.cs
index 03d59f93d0..f54e800d17 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsInt.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsInt.cs
@@ -13,6 +13,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class ConstantArgsInt
{
@@ -928,3 +930,4 @@ public static class ConstantArgsInt
return (result ? 100 : -1);
}
}
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsLong.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsLong.cs
index f4e45f50db..e5679f1638 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsLong.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsLong.cs
@@ -13,6 +13,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class ConstantArgsLong
{
@@ -928,3 +930,4 @@ public static class ConstantArgsLong
return (result ? 100 : -1);
}
}
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsSByte.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsSByte.cs
index b329122967..0ec29b8341 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsSByte.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsSByte.cs
@@ -13,6 +13,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class ConstantArgsSByte
{
@@ -928,3 +930,4 @@ public static class ConstantArgsSByte
return (result ? 100 : -1);
}
}
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsShort.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsShort.cs
index 8718111a72..f8cf23e8da 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsShort.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsShort.cs
@@ -13,6 +13,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class ConstantArgsShort
{
@@ -928,3 +930,4 @@ public static class ConstantArgsShort
return (result ? 100 : -1);
}
}
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsString.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsString.cs
index b7319086d7..38a3f7e6b9 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsString.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsString.cs
@@ -16,6 +16,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class ConstantArgsString
{
@@ -328,3 +330,4 @@ public static class ConstantArgsString
return (result ? 100 : -1);
}
}
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsUInt.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsUInt.cs
index db3316ea32..e3f6e2aae8 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsUInt.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsUInt.cs
@@ -13,6 +13,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class ConstantArgsUInt
{
@@ -888,3 +890,4 @@ public static class ConstantArgsUInt
return (result ? 100 : -1);
}
}
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsULong.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsULong.cs
index 72087077e2..7585a3e1fc 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsULong.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsULong.cs
@@ -13,6 +13,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class ConstantArgsULong
{
@@ -888,3 +890,4 @@ public static class ConstantArgsULong
return (result ? 100 : -1);
}
}
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsUShort.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsUShort.cs
index 249e985496..c96274e424 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsUShort.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/ConstantArgsUShort.cs
@@ -13,6 +13,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class ConstantArgsUShort
{
@@ -928,3 +930,4 @@ public static class ConstantArgsUShort
return (result ? 100 : -1);
}
}
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/InlineGCStruct.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/InlineGCStruct.cs
new file mode 100644
index 0000000000..660627cc72
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/InlineGCStruct.cs
@@ -0,0 +1,148 @@
+// 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.
+
+// In CoreCLR String.Format(ref, ref) is small and readily inlined.
+// The inline introduces a System.Parms GC struct local which is
+// untracked and must be zero initialized in the prolog. When the
+// inlined callsite is in a cold path, the inline hurts performance.
+//
+// There are two test methods below, one of which calls String.Format
+// on a cold path and the other which has similar structure but
+// does not call String.Format. Expectation is that they will have
+// similar performance.
+//
+// See https://github.com/dotnet/coreclr/issues/7569 for context.
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+namespace Inlining
+{
+public class InlineGCStruct
+{
+#if DEBUG
+ public const int Iterations = 1;
+#else
+ public const int Iterations = 2500000;
+#endif
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ public static int FastFunctionNotCallingStringFormat(int param)
+ {
+ if (param < 0)
+ {
+ throw new Exception(String.Format("We do not like the value {0:N0}.", param));
+ }
+
+ if (param == int.MaxValue)
+ {
+ throw new Exception(String.Format("{0:N0} is maxed out.", param));
+ }
+
+ if (param > int.MaxValue / 2)
+ {
+ throw new Exception(String.Format("We do not like the value {0:N0} either.", param));
+ }
+
+ return param * 2;
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ public static int FastFunctionNotHavingStringFormat(int param)
+ {
+ if (param < 0)
+ {
+ throw new ArgumentOutOfRangeException("param", "We do not like this value.");
+ }
+
+ if (param == int.MaxValue)
+ {
+ throw new ArgumentOutOfRangeException("param", "Maxed out.");
+ }
+
+ if (param > int.MaxValue / 2)
+ {
+ throw new ArgumentOutOfRangeException("param", "We do not like this value either.");
+ }
+
+ return param * 2;
+ }
+
+ [Benchmark]
+ public static bool WithFormat()
+ {
+ int result = 0;
+
+ foreach (var iteration in Benchmark.Iterations)
+ {
+ using (iteration.StartMeasurement())
+ {
+ for (int i = 0; i < Iterations; i++)
+ {
+ result |= FastFunctionNotCallingStringFormat(11);
+ }
+ }
+ }
+
+ return (result == 22);
+ }
+
+ [Benchmark]
+ public static bool WithoutFormat()
+ {
+ int result = 0;
+
+ foreach (var iteration in Benchmark.Iterations)
+ {
+ using (iteration.StartMeasurement())
+ {
+ for (int i = 0; i < Iterations; i++)
+ {
+ result |= FastFunctionNotHavingStringFormat(11);
+ }
+ }
+ }
+
+ return (result == 22);
+ }
+
+ public static bool WithoutFormatBase()
+ {
+ int result = 0;
+
+ for (int i = 0; i < Iterations; i++)
+ {
+ result |= FastFunctionNotHavingStringFormat(11);
+ }
+
+ return (result == 22);
+ }
+
+ public static bool WithFormatBase()
+ {
+ int result = 0;
+
+ for (int i = 0; i < Iterations; i++)
+ {
+ result |= FastFunctionNotCallingStringFormat(11);
+ }
+
+ return (result == 22);
+ }
+
+ public static int Main()
+ {
+ bool withFormat = WithFormatBase();
+ bool withoutFormat = WithoutFormatBase();
+
+ return (withFormat && withoutFormat ? 100 : -1);
+ }
+}
+}
+
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/InlineGCStruct.csproj b/tests/src/JIT/Performance/CodeQuality/Inlining/InlineGCStruct.csproj
new file mode 100644
index 0000000000..cb3381638c
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/InlineGCStruct.csproj
@@ -0,0 +1,44 @@
+<?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>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="InlineGCStruct.cs" />
+ </ItemGroup>
+ <PropertyGroup>
+ <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+ <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+ </PropertyGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project>
diff --git a/tests/src/JIT/Performance/CodeQuality/Inlining/NoThrowInline.cs b/tests/src/JIT/Performance/CodeQuality/Inlining/NoThrowInline.cs
index 9b689ce376..dc05f44b33 100644
--- a/tests/src/JIT/Performance/CodeQuality/Inlining/NoThrowInline.cs
+++ b/tests/src/JIT/Performance/CodeQuality/Inlining/NoThrowInline.cs
@@ -13,6 +13,8 @@ using Xunit;
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+namespace Inlining
+{
public static class NoThrowInline
{
#if DEBUG
@@ -34,7 +36,7 @@ public static class NoThrowInline
//
// We expect ThrowArgumentNullException to not be inlined into Bench, the throw code is pretty
- // large and throws are extremly slow. However, we need to be careful not to degrade the
+ // large and throws are extremly slow. However, we need to be careful not to degrade the
// non-exception path performance by preserving registers across the call. For this the compiler
// will have to understand that ThrowArgumentNullException never returns and omit the register
// preservation code.
@@ -73,3 +75,4 @@ public static class NoThrowInline
return (Bench("a", "bc", "def", "ghij") == 10) ? 100 : -1;
}
}
+}