Skip to content

Run fgValueNumberConstLoad for invariant loads #86154

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

Merged
merged 6 commits into from
May 15, 2023

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented May 12, 2023

We have a separate path for GTF_IND_INVARIANT where we could miss some optimization opportunites defined in fgValueNumberConstLoad

jit-diff:

Total bytes of base: 58746251
Total bytes of diff: 58741799
Total bytes of delta: -4452 (-0.01 % of base)
Total relative delta: NaN
    diff is an improvement.
    relative diff is a regression.


Total byte diff includes 103 bytes from reconciling methods
        Base had    0 unique methods,        0 unique bytes
        Diff had    1 unique methods,      103 unique bytes

Top file regressions (bytes):
         103 : Microsoft.CodeAnalysis.dasm (0.01% of base)

Top file improvements (bytes):
       -1499 : Newtonsoft.Json.dasm (-0.16% of base)
        -624 : xunit.execution.dotnet.dasm (-0.25% of base)
        -612 : System.ComponentModel.TypeConverter.dasm (-0.22% of base)
        -588 : xunit.runner.utility.netcoreapp10.dasm (-0.31% of base)
        -320 : System.Composition.Hosting.dasm (-0.37% of base)
        -261 : Microsoft.Diagnostics.Tracing.TraceEvent.dasm (-0.01% of base)
        -189 : System.Composition.TypedParts.dasm (-0.38% of base)
        -107 : System.Private.Xml.dasm (-0.00% of base)
        -100 : System.Linq.Expressions.dasm (-0.01% of base)
         -94 : System.ComponentModel.Composition.Registration.dasm (-0.10% of base)
         -47 : FSharp.Core.dasm (-0.01% of base)
         -41 : Microsoft.Extensions.DependencyInjection.Abstractions.dasm (-0.14% of base)
         -30 : System.Configuration.ConfigurationManager.dasm (-0.01% of base)
         -20 : System.ComponentModel.Composition.dasm (-0.01% of base)
         -13 : Microsoft.VisualBasic.Core.dasm (-0.00% of base)
         -10 : Microsoft.Diagnostics.FastSerialization.dasm (-0.00% of base)

17 total files with Code Size differences (16 improved, 1 regressed), 259 unchanged.

Top method improvements (bytes):
        -261 (-8.11% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - Microsoft.Diagnostics.Tracing.Etlx.TraceLog:InitializeFromFile(System.String):this
         -94 (-32.53% of base) : System.ComponentModel.Composition.Registration.dasm - System.ComponentModel.Composition.Registration.PartBuilder:MemberHasExportMetadata(System.Reflection.MemberInfo):bool
         -93 (-34.83% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[System.Nullable`1[int]]:AddNewCore():System.Object:this
         -89 (-32.01% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[System.Numerics.Vector`1[float]]:AddNewCore():System.Object:this
         -87 (-2.85% of base) : System.Private.Xml.dasm - System.Xml.Serialization.XmlSerializationReader:ReadArray(System.String,System.String):System.Array:this
         -86 (-41.95% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[double]:AddNewCore():System.Object:this
         -86 (-43.00% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[int]:AddNewCore():System.Object:this
         -86 (-42.79% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[long]:AddNewCore():System.Object:this
         -86 (-42.57% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[short]:AddNewCore():System.Object:this
         -86 (-42.79% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[ubyte]:AddNewCore():System.Object:this
         -86 (-35.68% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[System.Nullable`1[int]](System.String):System.Nullable`1[int]:this
         -86 (-35.68% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[System.Nullable`1[int]](System.String):System.Nullable`1[int]:this
         -84 (-32.68% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[double](System.String):double:this
         -84 (-32.68% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[double](System.String):double:this
         -84 (-33.33% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[int](System.String):int:this
         -84 (-33.33% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[int](System.String):int:this
         -84 (-33.20% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[long](System.String):long:this
         -84 (-33.20% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[long](System.String):long:this
         -84 (-33.07% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[short](System.String):short:this
         -84 (-33.07% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[short](System.String):short:this

Top method improvements (percentages):
         -86 (-43.00% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[int]:AddNewCore():System.Object:this
         -86 (-42.79% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[long]:AddNewCore():System.Object:this
         -86 (-42.79% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[ubyte]:AddNewCore():System.Object:this
         -86 (-42.57% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[short]:AddNewCore():System.Object:this
         -86 (-41.95% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[double]:AddNewCore():System.Object:this
         -86 (-35.68% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[System.Nullable`1[int]](System.String):System.Nullable`1[int]:this
         -86 (-35.68% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[System.Nullable`1[int]](System.String):System.Nullable`1[int]:this
         -93 (-34.83% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[System.Nullable`1[int]]:AddNewCore():System.Object:this
         -84 (-33.33% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[int](System.String):int:this
         -84 (-33.33% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[int](System.String):int:this
         -84 (-33.20% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[long](System.String):long:this
         -84 (-33.20% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[long](System.String):long:this
         -84 (-33.20% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[ubyte](System.String):ubyte:this
         -84 (-33.20% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[ubyte](System.String):ubyte:this
         -84 (-33.07% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[short](System.String):short:this
         -84 (-33.07% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[short](System.String):short:this
         -84 (-32.68% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[double](System.String):double:this
         -84 (-32.68% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[double](System.String):double:this
         -94 (-32.53% of base) : System.ComponentModel.Composition.Registration.dasm - System.ComponentModel.Composition.Registration.PartBuilder:MemberHasExportMetadata(System.Reflection.MemberInfo):bool
         -89 (-32.01% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[System.Numerics.Vector`1[float]]:AddNewCore():System.Object:this

109 total methods with Code Size differences (108 improved, 1 regressed), 376335 unchanged

diff example: https://www.diffchecker.com/ZF1cltJi/

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 12, 2023
@ghost ghost assigned EgorBo May 12, 2023
@ghost
Copy link

ghost commented May 12, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

We have a separate path for GTF_IND_INVARIANT where we could miss some optimization opportunites defined in fgValueNumberConstLoad

jit-diff:

Total bytes of base: 58746251
Total bytes of diff: 58741799
Total bytes of delta: -4452 (-0.01 % of base)
Total relative delta: NaN
    diff is an improvement.
    relative diff is a regression.


Total byte diff includes 103 bytes from reconciling methods
        Base had    0 unique methods,        0 unique bytes
        Diff had    1 unique methods,      103 unique bytes

Top file regressions (bytes):
         103 : Microsoft.CodeAnalysis.dasm (0.01% of base)

Top file improvements (bytes):
       -1499 : Newtonsoft.Json.dasm (-0.16% of base)
        -624 : xunit.execution.dotnet.dasm (-0.25% of base)
        -612 : System.ComponentModel.TypeConverter.dasm (-0.22% of base)
        -588 : xunit.runner.utility.netcoreapp10.dasm (-0.31% of base)
        -320 : System.Composition.Hosting.dasm (-0.37% of base)
        -261 : Microsoft.Diagnostics.Tracing.TraceEvent.dasm (-0.01% of base)
        -189 : System.Composition.TypedParts.dasm (-0.38% of base)
        -107 : System.Private.Xml.dasm (-0.00% of base)
        -100 : System.Linq.Expressions.dasm (-0.01% of base)
         -94 : System.ComponentModel.Composition.Registration.dasm (-0.10% of base)
         -47 : FSharp.Core.dasm (-0.01% of base)
         -41 : Microsoft.Extensions.DependencyInjection.Abstractions.dasm (-0.14% of base)
         -30 : System.Configuration.ConfigurationManager.dasm (-0.01% of base)
         -20 : System.ComponentModel.Composition.dasm (-0.01% of base)
         -13 : Microsoft.VisualBasic.Core.dasm (-0.00% of base)
         -10 : Microsoft.Diagnostics.FastSerialization.dasm (-0.00% of base)

17 total files with Code Size differences (16 improved, 1 regressed), 259 unchanged.

Top method regressions (bytes):
         103 (     ∞ of base) : Microsoft.CodeAnalysis.dasm - Microsoft.CodeAnalysis.SmallDictionary`2[System.__Canon,int]:LeftComplex(Microsoft.CodeAnalysis.SmallDictionary`2+AvlNode[System.__Canon,int]):Microsoft.CodeAnalysis.SmallDictionary`2+AvlNode[System.__Canon,int] (0 base, 1 diff methods)

Top method improvements (bytes):
        -261 (-8.11% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - Microsoft.Diagnostics.Tracing.Etlx.TraceLog:InitializeFromFile(System.String):this
         -94 (-32.53% of base) : System.ComponentModel.Composition.Registration.dasm - System.ComponentModel.Composition.Registration.PartBuilder:MemberHasExportMetadata(System.Reflection.MemberInfo):bool
         -93 (-34.83% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[System.Nullable`1[int]]:AddNewCore():System.Object:this
         -89 (-32.01% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[System.Numerics.Vector`1[float]]:AddNewCore():System.Object:this
         -87 (-2.85% of base) : System.Private.Xml.dasm - System.Xml.Serialization.XmlSerializationReader:ReadArray(System.String,System.String):System.Array:this
         -86 (-41.95% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[double]:AddNewCore():System.Object:this
         -86 (-43.00% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[int]:AddNewCore():System.Object:this
         -86 (-42.79% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[long]:AddNewCore():System.Object:this
         -86 (-42.57% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[short]:AddNewCore():System.Object:this
         -86 (-42.79% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[ubyte]:AddNewCore():System.Object:this
         -86 (-35.68% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[System.Nullable`1[int]](System.String):System.Nullable`1[int]:this
         -86 (-35.68% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[System.Nullable`1[int]](System.String):System.Nullable`1[int]:this
         -84 (-32.68% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[double](System.String):double:this
         -84 (-32.68% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[double](System.String):double:this
         -84 (-33.33% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[int](System.String):int:this
         -84 (-33.33% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[int](System.String):int:this
         -84 (-33.20% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[long](System.String):long:this
         -84 (-33.20% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[long](System.String):long:this
         -84 (-33.07% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[short](System.String):short:this
         -84 (-33.07% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[short](System.String):short:this

Top method regressions (percentages):
         103 (     ∞ of base) : Microsoft.CodeAnalysis.dasm - Microsoft.CodeAnalysis.SmallDictionary`2[System.__Canon,int]:LeftComplex(Microsoft.CodeAnalysis.SmallDictionary`2+AvlNode[System.__Canon,int]):Microsoft.CodeAnalysis.SmallDictionary`2+AvlNode[System.__Canon,int] (0 base, 1 diff methods)

Top method improvements (percentages):
         -86 (-43.00% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[int]:AddNewCore():System.Object:this
         -86 (-42.79% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[long]:AddNewCore():System.Object:this
         -86 (-42.79% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[ubyte]:AddNewCore():System.Object:this
         -86 (-42.57% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[short]:AddNewCore():System.Object:this
         -86 (-41.95% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[double]:AddNewCore():System.Object:this
         -86 (-35.68% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[System.Nullable`1[int]](System.String):System.Nullable`1[int]:this
         -86 (-35.68% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[System.Nullable`1[int]](System.String):System.Nullable`1[int]:this
         -93 (-34.83% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[System.Nullable`1[int]]:AddNewCore():System.Object:this
         -84 (-33.33% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[int](System.String):int:this
         -84 (-33.33% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[int](System.String):int:this
         -84 (-33.20% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[long](System.String):long:this
         -84 (-33.20% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[long](System.String):long:this
         -84 (-33.20% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[ubyte](System.String):ubyte:this
         -84 (-33.20% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[ubyte](System.String):ubyte:this
         -84 (-33.07% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[short](System.String):short:this
         -84 (-33.07% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[short](System.String):short:this
         -84 (-32.68% of base) : xunit.execution.dotnet.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[double](System.String):double:this
         -84 (-32.68% of base) : xunit.runner.utility.netcoreapp10.dasm - Xunit.Serialization.XunitSerializationInfo:GetValue[double](System.String):double:this
         -94 (-32.53% of base) : System.ComponentModel.Composition.Registration.dasm - System.ComponentModel.Composition.Registration.PartBuilder:MemberHasExportMetadata(System.Reflection.MemberInfo):bool
         -89 (-32.01% of base) : System.ComponentModel.TypeConverter.dasm - System.ComponentModel.BindingList`1[System.Numerics.Vector`1[float]]:AddNewCore():System.Object:this

109 total methods with Code Size differences (108 improved, 1 regressed), 376335 unchanged

diff example: https://www.diffchecker.com/ZF1cltJi/

Main use-case - field access for static readonly frozeObject (immutable)

Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented May 13, 2023

Build failure is unrelated (src/tests/JIT/opt/SSA/MemorySsa.csproj test failed to build and is fixed in #86176)

@jakobbotsch @SingleAccretion PTAL, this should produce more diffs when I enable more kinds of frozen objects

@EgorBo EgorBo requested a review from jakobbotsch May 13, 2023 08:51
@@ -10445,7 +10445,7 @@ bool Compiler::fgValueNumberConstLoad(GenTreeIndir* tree)
int size = (int)genTypeSize(tree->TypeGet());
const int maxElementSize = sizeof(simd_t);

if ((varTypeIsSIMD(tree) || varTypeIsIntegral(tree) || varTypeIsFloating(tree) || tree->TypeIs(TYP_REF)) &&
if (!tree->TypeIs(TYP_BYREF, TYP_STRUCT) &&
Copy link
Member Author

Choose a reason for hiding this comment

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

reversed type checks for TP

@EgorBo EgorBo merged commit 8995217 into dotnet:main May 15, 2023
@EgorBo EgorBo deleted the fold-more-frozen branch May 15, 2023 11:15
@ghost ghost locked as resolved and limited conversation to collaborators Jun 14, 2023
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.

3 participants