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: consistently mark method table accesses as invariant #45854

Merged
merged 2 commits into from
Dec 12, 2020

Conversation

AndyAyersMS
Copy link
Member

Introduce a new utility method to create the IR for method table access,
marking the resulting indir as invariant. This allows method table access
CSEs (which will be increasingly common with the advent of PGO-enabled
Guarded Devirtualization).

Add a workaround to assertion prop for method table to be able to see
through a CSE'd method table access.

Remove optimizer inhibitions related to colon cond, as there are no qmark
nodes around by this point.

Introduce a new utility method to create the IR for method table access,
marking the resulting indir as invariant. This allows method table access
CSEs (which will be increasingly common with the advent of PGO-enabled
Guarded Devirtualization).

Add a workaround to assertion prop for method table to be able to see
through a CSE'd method table access.

Remove optimizer inhibitions related to colon cond, as there are no qmark
nodes around by this point.
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 9, 2020
@AndyAyersMS
Copy link
Member Author

@briansull PTAL
cc @dotnet/jit-contrib

Relatively modest impact. Most regressions are extra CSEs. A couple of them are missed knock-on bounds checks caused by extra CSEs (see #45658). Large wins are in methods that have big chains of type tests guarding casts...

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 base: 50416759
Total bytes of diff: 50416678
Total bytes of delta: -81 (-0.00% of base)
    diff is an improvement.

Top file regressions (bytes):
         101 : Microsoft.CodeAnalysis.VisualBasic.dasm (0.00% of base)
          51 : System.Private.Xml.dasm (0.00% of base)
          33 : Microsoft.CodeAnalysis.CSharp.dasm (0.00% of base)
          30 : System.Collections.Immutable.dasm (0.00% of base)
          29 : System.Private.CoreLib.dasm (0.00% of base)
          20 : System.DirectoryServices.AccountManagement.dasm (0.01% of base)
          18 : System.Security.Cryptography.X509Certificates.dasm (0.01% of base)
          17 : System.Management.dasm (0.00% of base)
          10 : System.Configuration.ConfigurationManager.dasm (0.00% of base)
           9 : System.Data.Odbc.dasm (0.00% of base)
           6 : System.IO.FileSystem.Watcher.dasm (0.04% of base)
           6 : System.Resources.Extensions.dasm (0.02% of base)
           6 : Microsoft.CodeAnalysis.dasm (0.00% of base)
           6 : System.Resources.Writer.dasm (0.07% of base)
           5 : CommandLine.dasm (0.00% of base)
           3 : System.Reflection.Metadata.dasm (0.00% of base)
           3 : System.Text.Json.dasm (0.00% of base)
           2 : Microsoft.Diagnostics.Tracing.TraceEvent.dasm (0.00% of base)

Top file improvements (bytes):
        -294 : System.Data.Common.dasm (-0.02% of base)
         -71 : FSharp.Core.dasm (-0.00% of base)
         -34 : System.Security.AccessControl.dasm (-0.04% of base)
         -29 : System.DirectoryServices.dasm (-0.01% of base)
          -8 : System.Private.DataContractSerialization.dasm (-0.00% of base)

23 total files with Code Size differences (5 improved, 18 regressed), 245 unchanged.

Top method regressions (bytes):
         102 ( 4.10% of base) : System.Data.Common.dasm - <>c__DisplayClass16_0:<GetLinqDataView>b__0(DataRow):bool:this (7 methods)
          39 ( 2.78% of base) : System.Private.Xml.dasm - XmlQueryRuntime:ChangeTypeXsltArgument(XmlQueryType,Object,Type):Object:this
          39 ( 1.16% of base) : System.Private.Xml.dasm - XmlSerializationWriterCodeGen:WriteValue(Object):this
          30 ( 0.71% of base) : Microsoft.CodeAnalysis.VisualBasic.dasm - Binder:BindFieldAndPropertyInitializers(SourceMemberContainerTypeSymbol,ImmutableArray`1,SynthesizedInteractiveInitializerMethod,DiagnosticBag):ImmutableArray`1
          30 ( 1.47% of base) : System.Collections.Immutable.dasm - ImmutableExtensions:TryCopyTo(IEnumerable`1,ref,int):bool (7 methods)
          29 ( 2.77% of base) : System.Private.CoreLib.dasm - Array:Copy(Array,int,Array,int,int,bool)
          21 ( 0.52% of base) : Microsoft.CodeAnalysis.VisualBasic.dasm - Parser:ParseIfExpression():ExpressionSyntax:this
          17 ( 4.14% of base) : System.Data.Common.dasm - FunctionNode:Bind(DataTable,List`1):this
          15 ( 1.34% of base) : System.DirectoryServices.AccountManagement.dasm - AccountInfo:LoadValueIntoProperty(String,Object):this
          12 ( 0.36% of base) : Microsoft.CodeAnalysis.CSharp.dasm - SyntaxTreeSemanticModel:CreateMemberModel(CSharpSyntaxNode):MemberSemanticModel:this
          12 ( 1.33% of base) : Microsoft.CodeAnalysis.VisualBasic.dasm - VBSemanticModel:GetNamedArgumentSymbolInfo(IdentifierNameSyntax,CancellationToken):SymbolInfo:this
          11 ( 0.82% of base) : System.Management.dasm - ManagementObjectSearcher:Get(ManagementOperationObserver):this
          11 ( 0.72% of base) : Microsoft.CodeAnalysis.VisualBasic.dasm - SyntaxTreeSemanticModel:GetCrefOrNameAttributeReferenceSymbols(VisualBasicSyntaxNode,bool,byref):ImmutableArray`1:this
           9 ( 0.63% of base) : System.Data.Common.dasm - DbCommandBuilder:BuildCache(bool,DataRow,bool):this
           8 ( 1.42% of base) : System.Private.Xml.dasm - AllElementsContentValidator:ExpectedElements(ValidationState,bool):ArrayList:this
           7 ( 2.24% of base) : System.Data.Odbc.dasm - OdbcMetaDataFactory:DataTableFromDataReaderProcedureColumns(IDataReader,String,bool):DataTable:this
           7 ( 1.08% of base) : System.Private.Xml.dasm - AllElementsContentValidator:ExpectedParticles(ValidationState,bool,XmlSchemaSet):ArrayList:this
           6 ( 0.22% of base) : System.Configuration.ConfigurationManager.dasm - ConfigurationElement:Unmerge(ConfigurationElement,ConfigurationElement,int):this
           6 ( 0.52% of base) : System.IO.FileSystem.Watcher.dasm - FileSystemWatcher:WaitForChanged(int,int):WaitForChangedResult:this
           6 ( 0.38% of base) : System.Resources.Extensions.dasm - PreserializedResourceWriter:WriteValue(int,Object,BinaryWriter):this

Top method improvements (bytes):
        -239 (-21.28% of base) : System.Data.Common.dasm - BigIntegerStorage:ConvertToBigInteger(Object,IFormatProvider):BigInteger
        -138 (-4.89% of base) : System.Data.Common.dasm - XSDSchema:HandleElementColumn(XmlSchemaElement,DataTable,bool):this
         -62 (-31.47% of base) : FSharp.Core.dasm - Joint:GetHashCode(IEqualityComparer):int:this
         -58 (-6.33% of base) : System.Data.Common.dasm - ConstraintCollection:Add(Constraint,bool):this
         -34 (-0.76% of base) : System.Security.AccessControl.dasm - CommonAcl:RemoveQualifiedAces(SecurityIdentifier,int,int,ubyte,bool,int,Guid,Guid):bool:this
         -33 (-1.34% of base) : System.Private.Xml.dasm - Compiler:IsValidRestriction(XmlSchemaParticle,XmlSchemaParticle):bool:this
         -29 (-2.20% of base) : System.DirectoryServices.dasm - DirectoryServer:GetOutboundConnectionsHelper():ReplicationConnectionCollection:this
         -18 (-1.28% of base) : System.Private.Xml.dasm - ReflectionXmlSerializationWriter:WritePrimitiveValue(TypeDesc,Object,bool,byref):bool:this
          -8 (-2.27% of base) : System.Private.DataContractSerialization.dasm - SchemaExporter:ExportDataContract(DataContract):this
          -3 (-0.13% of base) : FSharp.Core.dasm - FSharpMap`2:Equals(Object):bool:this (7 methods)
          -3 (-0.16% of base) : FSharp.Core.dasm - FSharpMap`2:System.IComparable.CompareTo(Object):int:this (7 methods)
          -3 (-0.13% of base) : FSharp.Core.dasm - FSharpSet`1:Equals(Object):bool:this (7 methods)

Top method regressions (percentages):
          17 ( 4.14% of base) : System.Data.Common.dasm - FunctionNode:Bind(DataTable,List`1):this
         102 ( 4.10% of base) : System.Data.Common.dasm - <>c__DisplayClass16_0:<GetLinqDataView>b__0(DataRow):bool:this (7 methods)
          39 ( 2.78% of base) : System.Private.Xml.dasm - XmlQueryRuntime:ChangeTypeXsltArgument(XmlQueryType,Object,Type):Object:this
          29 ( 2.77% of base) : System.Private.CoreLib.dasm - Array:Copy(Array,int,Array,int,int,bool)
           3 ( 2.52% of base) : System.Private.Xml.dasm - XmlQueryTypeFactory:Serialize(BinaryWriter,XmlQueryType)
           3 ( 2.26% of base) : System.Security.Cryptography.X509Certificates.dasm - FindPal:ConfirmedCast(Object):int
           7 ( 2.24% of base) : System.Data.Odbc.dasm - OdbcMetaDataFactory:DataTableFromDataReaderProcedureColumns(IDataReader,String,bool):DataTable:this
           3 ( 2.24% of base) : System.Security.Cryptography.X509Certificates.dasm - FindPal:ConfirmedCast(Object):ubyte
           3 ( 2.24% of base) : System.Security.Cryptography.X509Certificates.dasm - FindPal:ConfirmedCast(Object):long
           3 ( 2.22% of base) : System.Security.Cryptography.X509Certificates.dasm - FindPal:ConfirmedCast(Object):short
           3 ( 2.17% of base) : System.Security.Cryptography.X509Certificates.dasm - FindPal:ConfirmedCast(Object):double
           3 ( 1.96% of base) : System.Security.Cryptography.X509Certificates.dasm - FindPal:ConfirmedCast(Object):Vector`1
          30 ( 1.47% of base) : System.Collections.Immutable.dasm - ImmutableExtensions:TryCopyTo(IEnumerable`1,ref,int):bool (7 methods)
           8 ( 1.42% of base) : System.Private.Xml.dasm - AllElementsContentValidator:ExpectedElements(ValidationState,bool):ArrayList:this
          15 ( 1.34% of base) : System.DirectoryServices.AccountManagement.dasm - AccountInfo:LoadValueIntoProperty(String,Object):this
          12 ( 1.33% of base) : Microsoft.CodeAnalysis.VisualBasic.dasm - VBSemanticModel:GetNamedArgumentSymbolInfo(IdentifierNameSyntax,CancellationToken):SymbolInfo:this
          39 ( 1.16% of base) : System.Private.Xml.dasm - XmlSerializationWriterCodeGen:WriteValue(Object):this
           7 ( 1.08% of base) : System.Private.Xml.dasm - AllElementsContentValidator:ExpectedParticles(ValidationState,bool,XmlSchemaSet):ArrayList:this
           3 ( 1.06% of base) : System.Text.Json.dasm - JsonConverter`1:TryWriteDataExtensionProperty(Utf8JsonWriter,__Canon,JsonSerializerOptions,byref):bool:this
           3 ( 0.87% of base) : Microsoft.CodeAnalysis.dasm - MetadataWriter:GetConstantTypeCode(Object):ubyte

Top method improvements (percentages):
         -62 (-31.47% of base) : FSharp.Core.dasm - Joint:GetHashCode(IEqualityComparer):int:this
        -239 (-21.28% of base) : System.Data.Common.dasm - BigIntegerStorage:ConvertToBigInteger(Object,IFormatProvider):BigInteger
         -58 (-6.33% of base) : System.Data.Common.dasm - ConstraintCollection:Add(Constraint,bool):this
        -138 (-4.89% of base) : System.Data.Common.dasm - XSDSchema:HandleElementColumn(XmlSchemaElement,DataTable,bool):this
          -8 (-2.27% of base) : System.Private.DataContractSerialization.dasm - SchemaExporter:ExportDataContract(DataContract):this
         -29 (-2.20% of base) : System.DirectoryServices.dasm - DirectoryServer:GetOutboundConnectionsHelper():ReplicationConnectionCollection:this
         -33 (-1.34% of base) : System.Private.Xml.dasm - Compiler:IsValidRestriction(XmlSchemaParticle,XmlSchemaParticle):bool:this
         -18 (-1.28% of base) : System.Private.Xml.dasm - ReflectionXmlSerializationWriter:WritePrimitiveValue(TypeDesc,Object,bool,byref):bool:this
         -34 (-0.76% of base) : System.Security.AccessControl.dasm - CommonAcl:RemoveQualifiedAces(SecurityIdentifier,int,int,ubyte,bool,int,Guid,Guid):bool:this
          -3 (-0.16% of base) : FSharp.Core.dasm - FSharpMap`2:System.IComparable.CompareTo(Object):int:this (7 methods)
          -3 (-0.13% of base) : FSharp.Core.dasm - FSharpMap`2:Equals(Object):bool:this (7 methods)
          -3 (-0.13% of base) : FSharp.Core.dasm - FSharpSet`1:Equals(Object):bool:this (7 methods)

65 total methods with Code Size differences (12 improved, 53 regressed), 258771 unchanged.

@@ -2111,11 +2114,6 @@ void Compiler::optAssertionGen(GenTree* tree)
{
tree->ClearAssertion();

if (tree->gtFlags & GTF_COLON_COND)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is GTF_COLON_COND dead code that is being removed with this change?
Maybe change it to an assert here.

I don't believe that we can create an assertion that is predicated on a conditional

Copy link
Member Author

Choose a reason for hiding this comment

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

We remove QMARKS in morph, so perhaps this is too aggressive. I'll restore the bail out but only do it for local assertion prop.

// original tree, of not.
//
inline GenTree* GenTree::gtUnwrapCSE()
{
Copy link
Contributor

@briansull briansull Dec 10, 2020

Choose a reason for hiding this comment

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

While this is the format that we use for a CSE def there are several other places we will generate GT_COMMA's with this patterm.
Looking through the code base this function also is commonly used to generate an assignment to a new temp LclVar

GenTree* Compiler::fgInsertCommaFormTemp(GenTree** ppTree, CORINFO_CLASS_HANDLE structType /*= nullptr*/)

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't have to be a CSE, it could be any value. I can rename the helper.

During global prop we have a mixture of rules that key off VNs and also look at IR shapes. In general we should just be able to use the VNs to figure most things out, but that doesn't happen consistently today. So in this case I need to find the original IR shape.

@AndyAyersMS
Copy link
Member Author

@dotnet/jit-contrib ping

Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

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

You removed some GTF_EXCEPT bits; I presume you've proved those are unnecessary, despite the comments there saying "null pointer exception"?

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.

Looks Good

@AndyAyersMS
Copy link
Member Author

You removed some GTF_EXCEPT bits; I presume you've proved those are unnecessary,

The new helper goes through gtNewIndir which invokes SetIndirExceptionFlags which typically adds GTF_EXCEPT unless it can prove otherwise. So we actually see more GTF_EXCEPT bits get set with this change.

@AndyAyersMS AndyAyersMS merged commit bc12def into dotnet:master Dec 12, 2020
@AndyAyersMS AndyAyersMS deleted the VtableIsInvariant branch December 12, 2020 01:40
@AndyAyersMS AndyAyersMS mentioned this pull request Jan 7, 2021
54 tasks
@ghost ghost locked as resolved and limited conversation to collaborators Jan 11, 2021
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.

4 participants