Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Generate non-null assertion for byrefs if we can't find corresponding refs #21944

Merged
merged 1 commit into from
Jan 12, 2019

Conversation

erozenfeld
Copy link
Member

When we have a non-null fact about a byref, we try to find the corresponding
ref and generate an assertion about the ref. Then it can be used on byrefs if the offset is not too big.
We use both trees and value numbers to find the ref. When the ref wasn't found we bailed on generating
the assertion.

I found that we get a number of good diffs if we generate assertions for byrefs when refs can't be found
so this change enables that.

@erozenfeld erozenfeld requested a review from briansull January 10, 2019 22:54
@erozenfeld
Copy link
Member Author

Framework x64 diffs:

Found 75 files with textual diffs.
PMI Diffs for System.Private.CoreLib.dll, framework assemblies for  default jit
Summary:
(Lower is better)
Total bytes of diff: -27488 (-0.07% of base)
    diff is an improvement.
Top file improvements by size (bytes):
       -8451 : System.Private.Xml.dasm (-0.23% of base)
       -3051 : System.Net.Http.dasm (-0.55% of base)
       -2451 : NuGet.Protocol.Core.v3.dasm (-0.96% of base)
       -1978 : System.Private.CoreLib.dasm (-0.05% of base)
       -1584 : Microsoft.CodeAnalysis.VisualBasic.dasm (-0.03% of base)
60 total files with size differences (60 improved, 0 regressed), 69 unchanged.
Top method regressions by size (bytes):
         131 ( 1.03% of base) : System.Reflection.Metadata.dasm - MetadataReader:InitializeTableReaders(struct,ubyte,ref,ref):this
          44 ( 0.78% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - ProviderManifest:ParseProviderEvents(ref,bool):this
          24 ( 0.38% of base) : Microsoft.CodeAnalysis.CSharp.dasm - SourceAssemblySymbol:DecodeWellKnownAttribute(byref,int,bool):this
          19 ( 0.33% of base) : Microsoft.CodeAnalysis.VisualBasic.dasm - SourceAssemblySymbol:DecodeWellKnownAttribute(byref):this
          16 ( 0.29% of base) : System.Private.Xml.dasm - XmlSerializationReader:ReadTypedPrimitive(ref,bool):ref:this
Top method improvements by size (bytes):
        -372 (-2.09% of base) : NuGet.Protocol.Core.v3.dasm - <TryCreate>d__1:MoveNext():this (20 methods)
        -256 (-2.27% of base) : System.Text.RegularExpressions.dasm - RegexWriter:EmitFragment(int,ref,int):this (2 methods)
        -244 (-1.65% of base) : System.Net.Http.dasm - <SendAsyncCore>d__56:MoveNext():this
        -184 (-4.90% of base) : System.Net.HttpListener.dasm - <CloseOutputAsyncCore>d__50:MoveNext():this
        -156 (-1.66% of base) : NuGet.Protocol.Core.v3.dasm - <StartWithTimeout>d__0`1:MoveNext():this (5 methods)
Top method regressions by size (percentage):
           4 ( 2.25% of base) : Microsoft.CodeAnalysis.VisualBasic.dasm - AnonymousTypeDescriptor:Equals(struct):bool:this
           5 ( 1.16% of base) : Microsoft.CodeAnalysis.dasm - SyntaxNodeOrTokenList:InsertRange(int,ref):struct:this
         131 ( 1.03% of base) : System.Reflection.Metadata.dasm - MetadataReader:InitializeTableReaders(struct,ubyte,ref,ref):this
          44 ( 0.78% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - ProviderManifest:ParseProviderEvents(ref,bool):this
           6 ( 0.73% of base) : Microsoft.CodeAnalysis.VisualBasic.dasm - DeclarationTreeBuilder:GetModifiers(struct):int
Top method improvements by size (percentage):
          -4 (-30.77% of base) : Microsoft.CSharp.dasm - ExpressionBinder:get_ContextForMemberLookup():ref:this
         -15 (-24.19% of base) : Microsoft.CodeAnalysis.VisualBasic.dasm - AnonymousTypePropertyPublicSymbol:get_Name():ref:this
         -12 (-21.82% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - TraceCodeAddresses:Address(int):long:this
         -12 (-18.75% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - TraceCodeAddress:get_Address():long:this
         -22 (-18.64% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - TraceCodeAddresses:<ForAllUnresolvedCodeAddressesInRange>b__34_0(int,int):int:this
1864 total methods with size differences (1844 improved, 20 regressed), 191570 unchanged.

@erozenfeld
Copy link
Member Author

Regressions are caused either by exceeding the max number of assertions or by downstream register allocation differences.

@erozenfeld
Copy link
Member Author

erozenfeld commented Jan 10, 2019

Example of a good dff:
AnonymousTypePropertyPublicSymbol:get_Name()

G_M43163_IG01:
       sub      rsp, 40
       nop      

G_M43163_IG02:
       mov      rax, gword ptr [rcx+8]
       mov      rax, gword ptr [rax+104]
       mov      edx, dword ptr [rcx+32]
       cmp      edx, dword ptr [rax+8]
       jae      SHORT G_M43163_IG04
       movsxd   rdx, edx
       shl      rdx, 5
       lea      rax, bword ptr [rax+rdx+16]
      -mov      rdx, gword ptr [rax]
      +mov      rax, gword ptr [rax]
      -mov      rcx, gword ptr [rax+8]
      -mov      rcx, gword ptr [rax+16]
      -movzx    rax, byte  ptr [rax+24]
      -mov      rax, rdx

G_M43163_IG03:
       add      rsp, 40
       ret      

G_M43163_IG04:
       call     CORINFO_HELP_RNGCHKFAIL
       int3     

-; Total bytes of code 62, prolog size 5 for method AnonymousTypePropertyPublicSymbol:get_Name():ref:this
+; Total bytes of code 47, prolog size 5 for method AnonymousTypePropertyPublicSymbol:get_Name():ref:this

@erozenfeld
Copy link
Member Author

@briansull @dotnet/jit-contrib PTAL

@benaadams
Copy link
Member

Aside: Annotating the code block with diff e.g. ```diff and moving +/- to start of line will give highlighting

G_M43163_IG01:
       sub      rsp, 40
       nop      

G_M43163_IG02:
       mov      rax, gword ptr [rcx+8]
       mov      rax, gword ptr [rax+104]
       mov      edx, dword ptr [rcx+32]
       cmp      edx, dword ptr [rax+8]
       jae      SHORT G_M43163_IG04
       movsxd   rdx, edx
       shl      rdx, 5
       lea      rax, bword ptr [rax+rdx+16]
-      mov      rdx, gword ptr [rax]
+      mov      rax, gword ptr [rax]
-      mov      rcx, gword ptr [rax+8]
-      mov      rcx, gword ptr [rax+16]
-      movzx    rax, byte  ptr [rax+24]
-      mov      rax, rdx

G_M43163_IG03:
       add      rsp, 40
       ret      

G_M43163_IG04:
       call     CORINFO_HELP_RNGCHKFAIL
       int3     

-; Total bytes of code 62, prolog size 5 for method AnonymousTypePropertyPublicSymbol:get_Name():ref:this
+; Total bytes of code 47, prolog size 5 for method AnonymousTypePropertyPublicSymbol:get_Name():ref:this

Copy link

@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.

Looks Good

@@ -957,7 +957,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,
}
}

if (fgIsBigOffset(offset) || (vnStore->TypeOfVN(vn) != TYP_REF))

Choose a reason for hiding this comment

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

You also should update the comment on line: 926:

// so only make non-null assertions about GC refs

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

… refs.

When we have a non-null fact about a byref, we try to find the corresponding
ref and generate an assertion about the ref. Then it can be used on byrefs if the offset is not too big.
We use both trees and value numbers to find the ref. When the ref wasn't found we bailed on generating
the assertion.

I found that we get a number of good diffs if we generate assertions for byrefs when refs can't be found
so this change enables that.
@erozenfeld erozenfeld force-pushed the AssertionPropImprovements branch from 293bca2 to cb05aa8 Compare January 11, 2019 00:48
@erozenfeld erozenfeld merged commit 4bda36a into dotnet:master Jan 12, 2019
@erozenfeld erozenfeld deleted the AssertionPropImprovements branch January 12, 2019 00:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants