Inliner: avoid inlining callees with GC structs on cold paths
authorAndy Ayers <andya@microsoft.com>
Thu, 13 Oct 2016 01:00:13 +0000 (18:00 -0700)
committerAndy Ayers <andya@microsoft.com>
Wed, 19 Oct 2016 19:17:35 +0000 (12:17 -0700)
commit5251ffccebe4f5801c77a271ec3ea52f27379a66
tree874d5f6cbf7e88b933aea583aaf453d6037133d0
parent4a5b68bb3169171f115fc6bfa764be8156d6e795
Inliner: avoid inlining callees with GC structs on cold paths

If an inline introduces a local or temp GC struct, the initialization
of that struct is done in the root method prolog. This can hurt
performance if the inline call site is cold. Detect this during
importation and update the inline policy to back out of the inline if
the inline is an always or discretionary candidate.

Jit diffs shows size wins in the core library with no regressions.
```
Total bytes of diff: -8789 (-0.29 % of base)
    diff is an improvement.
Total byte diff includes 0 bytes from reconciling methods
        Base had    0 unique methods,        0 unique bytes
        Diff had    0 unique methods,        0 unique bytes
Top file improvements by size (bytes):
       -8789 : System.Private.CoreLib.dasm (-0.29 % of base)
1 total files with size differences.
Top method improvements by size (bytes):
        -320 : System.Private.CoreLib.dasm - FrameSecurityDescriptor:CheckDemand2(ref,ref,long,bool):bool:this
        -224 : System.Private.CoreLib.dasm - RuntimeConstructorInfo:CheckCanCreateInstance(ref,bool)
        -214 : System.Private.CoreLib.dasm - RuntimeType:GetMethodBase(ref,long):ref
        -150 : System.Private.CoreLib.dasm - CultureInfo:GetCultureInfoByIetfLanguageTag(ref):ref
        -146 : System.Private.CoreLib.dasm - GC:RegisterForFullGCNotification(int,int)
103 total methods with size differences.
```
Desktop testing shows similar wins in a number of places and only
a few sparse small regressions.

Added a perf test. Thanks to @hypersw for noticing this.

Closes dotnet/coreclr#7569.

Commit migrated from https://github.com/dotnet/coreclr/commit/1e0359ce3e5d25ba4dbbe72336653ea1c94113ac
src/coreclr/src/jit/importer.cpp
src/coreclr/src/jit/inline.def
src/coreclr/src/jit/inlinepolicy.cpp
src/coreclr/tests/src/JIT/Performance/CodeQuality/Inlining/InlineGCStruct.cs [new file with mode: 0644]
src/coreclr/tests/src/JIT/Performance/CodeQuality/Inlining/InlineGCStruct.csproj [new file with mode: 0644]