Skip to content
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

JIT: remove inlining restriction for some methods that throw #2232

Merged
merged 2 commits into from
Jan 29, 2020

Conversation

AndyAyersMS
Copy link
Member

We were blocking inlines for methods that throw with more than one thing on the
evaluation stack. There was already logic for the non-inlining case to flush
the stack and preserve pending side effects. So we can simply remove the
inlining restriction.

Fixes #2156.

We were blocking inlines for methods that throw with more than one thing on the
evaluation stack. There was already logic for the non-inlining case to flush
the stack and preserve pending side effects. So we can simply remove the
inlining restriction.

Fixes dotnet#2156.
@AndyAyersMS
Copy link
Member Author

cc @dotnet/jit-contrib

PMI diffs shows a few cases where inlining is unblocked; all cause code size increases.

PMI CodeSize Diffs for System.Private.CoreLib.dll, framework assemblies for x64 default jit
Summary of Code Size diffs:
(Lower is better)
Total bytes of diff: 566 (0.00% of base)
    diff is a regression.
Top file regressions (bytes):
         180 : System.Composition.AttributedModel.dasm (29.80% of base)
         161 : System.Private.CoreLib.dasm (0.00% of base)
         133 : System.Security.Cryptography.Pkcs.dasm (0.03% of base)
          63 : System.DirectoryServices.Protocols.dasm (0.07% of base)
          29 : System.Runtime.Numerics.dasm (0.04% of base)
5 total files with Code Size differences (0 improved, 5 regressed), 160 unchanged.
Top method regressions (bytes):
         161 (22.39% of base) : System.Private.CoreLib.dasm - CustomAttributeData:get_NamedArguments():IList`1:this
         133 (36.34% of base) : System.Security.Cryptography.Pkcs.dasm - PkcsHelpers:DeepCopy(CmsRecipientCollection):CmsRecipientCollection
          96 (457.14% of base) : System.Composition.AttributedModel.dasm - SharedAttribute:.ctor(String):this
          84 (400.00% of base) : System.Composition.AttributedModel.dasm - SharedAttribute:.ctor():this
          63 (14.58% of base) : System.DirectoryServices.Protocols.dasm - AddRequest:.ctor(String,String):this
          29 ( 7.67% of base) : System.Runtime.Numerics.dasm - BigNumber:HexNumberToBigInteger(byref,byref):bool
Top method regressions (percentages):
          96 (457.14% of base) : System.Composition.AttributedModel.dasm - SharedAttribute:.ctor(String):this
          84 (400.00% of base) : System.Composition.AttributedModel.dasm - SharedAttribute:.ctor():this
         133 (36.34% of base) : System.Security.Cryptography.Pkcs.dasm - PkcsHelpers:DeepCopy(CmsRecipientCollection):CmsRecipientCollection
         161 (22.39% of base) : System.Private.CoreLib.dasm - CustomAttributeData:get_NamedArguments():IList`1:this
          63 (14.58% of base) : System.DirectoryServices.Protocols.dasm - AddRequest:.ctor(String,String):this
          29 ( 7.67% of base) : System.Runtime.Numerics.dasm - BigNumber:HexNumberToBigInteger(byref,byref):bool
6 total methods with Code Size differences (0 improved, 6 regressed), 244490 unchanged.

SPMI shows one beneficial inline:

         -63 (-12.73% of base) : 377923.dasm - System.DirectoryServices.Protocols.AddRequest:.ctor(System.String,System.String):this

@sandreenko sandreenko added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jan 27, 2020
@briansull
Copy link
Contributor

briansull commented Jan 27, 2020

If you gather PerfScore diffs on this chnage there shouldn't be much of a regression, as the block is marked as RarelyRun (with a weight of zero). The remaining diffs will be based upon codesize and will be greatly reduced:

emit.h:1321:#define PERFSCORE_CODESIZE_COST_HOT 0.10f
emit.h:1322:#define PERFSCORE_CODESIZE_COST_COLD 0.01f

However sometimes extra code in the Cold region can cause changes in register usage (extra callee saves, extra spills , etc..) in the hot regions and looking into those can often reveal area that we can improve upon.

@AndyAyersMS
Copy link
Member Author

This change allows inlining of some methods with conditional throws. The throw block will be rarely run, but the rest of the inlined method won't be. So perf scores end up higher too.

Summary of Perf Score diffs:
(Lower is better)

Total PerfScoreUnits of diff: 84.47 (0.00% of base)
    diff is a regression.

Top file regressions (PerfScoreUnits):
       30.50 : System.Composition.AttributedModel.dasm (15.91% of base)
       21.30 : System.Security.Cryptography.Pkcs.dasm (0.02% of base)
       19.10 : System.Private.CoreLib.dasm (0.00% of base)
        7.80 : System.DirectoryServices.Protocols.dasm (0.02% of base)
        5.77 : System.Runtime.Numerics.dasm (0.02% of base)

5 total files with Perf Score differences (0 improved, 5 regressed), 160 unchanged.

Top method regressions (PerfScoreUnits):
       21.30 (10.89% of base) : System.Security.Cryptography.Pkcs.dasm - PkcsHelpers:DeepCopy(CmsRecipientCollection):CmsRecipientCollection
       19.10 ( 4.38% of base) : System.Private.CoreLib.dasm - CustomAttributeData:get_NamedArguments():IList`1:this
       17.10 (259.09% of base) : System.Composition.AttributedModel.dasm - SharedAttribute:.ctor(String):this
       13.40 (203.03% of base) : System.Composition.AttributedModel.dasm - SharedAttribute:.ctor():this
        7.80 ( 7.75% of base) : System.DirectoryServices.Protocols.dasm - AddRequest:.ctor(String,String):this
        5.77 ( 3.22% of base) : System.Runtime.Numerics.dasm - BigNumber:HexNumberToBigInteger(byref,byref):bool

Top method regressions (percentages):
       17.10 (259.09% of base) : System.Composition.AttributedModel.dasm - SharedAttribute:.ctor(String):this
       13.40 (203.03% of base) : System.Composition.AttributedModel.dasm - SharedAttribute:.ctor():this
       21.30 (10.89% of base) : System.Security.Cryptography.Pkcs.dasm - PkcsHelpers:DeepCopy(CmsRecipientCollection):CmsRecipientCollection
        7.80 ( 7.75% of base) : System.DirectoryServices.Protocols.dasm - AddRequest:.ctor(String,String):this
       19.10 ( 4.38% of base) : System.Private.CoreLib.dasm - CustomAttributeData:get_NamedArguments():IList`1:this
        5.77 ( 3.22% of base) : System.Runtime.Numerics.dasm - BigNumber:HexNumberToBigInteger(byref,byref):bool

6 total methods with Perf Score differences (0 improved, 6 regressed), 244490 unchanged.

Copy link
Contributor

@sandreenko sandreenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@briansull briansull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AndyAyersMS AndyAyersMS merged commit 110af6e into dotnet:master Jan 29, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible JIT inlining optimization: removing multiple argument null checks
3 participants