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

Annotate handle indirections with GTF_IND_INVARIANT and add validation to fgDebugCheckFlags #42021

Merged
merged 18 commits into from
Sep 21, 2020

Conversation

briansull
Copy link
Contributor

This change allows us to CSE many additional indirections involving class, method and other handles.
It is a performance improvement

@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 Sep 9, 2020
@briansull briansull changed the title [WIP] Annotate handle indirections with GTF_IND_INVARIANT and add validation to fgDebugCheckFlags Annotate handle indirections with GTF_IND_INVARIANT and add validation to fgDebugCheckFlags Sep 15, 2020
@briansull
Copy link
Contributor Author

briansull commented Sep 15, 2020

Crossgen 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: 33817028
Total bytes of diff: 33442702
Total bytes of delta: -374326 (-1.11% of base)
    diff is an improvement.
|
Top file improvements (bytes):
     -236072 : Microsoft.Diagnostics.Tracing.TraceEvent.dasm (-7.27% of base)
      -18977 : Microsoft.CodeAnalysis.CSharp.dasm (-0.92% of base)
      -16553 : Microsoft.CodeAnalysis.VisualBasic.dasm (-0.73% of base)
      -11989 : System.Data.Common.dasm (-1.08% of base)
      -11623 : System.Private.DataContractSerialization.dasm (-1.62% of base)
       -8313 : System.Private.Xml.dasm (-0.27% of base)
       -5970 : System.DirectoryServices.dasm (-1.57% of base)
       -4216 : System.Data.OleDb.dasm (-1.58% of base)
       -3536 : System.Data.Odbc.dasm (-1.96% of base)
Top file regressions (bytes):
         293 : xunit.runner.utility.netcoreapp10.dasm (0.21% of base)
          62 : System.CodeDom.dasm (0.04% of base)
          52 : System.Memory.dasm (0.06% of base)

Top method improvements (percentages):
         -63 (-51.22% of base) : System.Private.DataContractSerialization.dasm - System.Runtime.Serialization.ExtensionDataReader:Reset():this
         -13 (-50.00% of base) : Microsoft.Win32.Registry.dasm - Microsoft.Win32.RegistryKey:SetDirty():this
         -77 (-45.29% of base) : System.Private.DataContractSerialization.dasm - System.Runtime.Serialization.Json.XmlJsonWriter:InitializeWriter():this
         -49 (-44.14% of base) : System.IO.Pipes.dasm - System.IO.Pipes.PipeStream:Init(int,int,int):this
         -49 (-43.75% of base) : System.Security.Cryptography.X509Certificates.dasm - System.Security.Cryptography.X509Certificates.X509Certificate2:Reset():this
         -21 (-42.86% of base) : System.DirectoryServices.AccountManagement.dasm - System.DirectoryServices.AccountManagement.RangeRetriever:Reset():this
         -68 (-42.50% of base) : System.Data.OleDb.dasm - System.Data.OleDb.OleDbParameter:CloneHelperCore(System.Data.OleDb.OleDbParameter):this
         -21 (-41.18% of base) : System.ServiceProcess.ServiceController.dasm - System.ServiceProcess.ServiceController:Refresh():this
         -21 (-39.62% of base) : System.Private.Xml.Linq.dasm - System.Xml.Linq.XNodeReader:Close():this
         -78 (-38.61% of base) : System.Private.DataContractSerialization.dasm - System.Runtime.Serialization.ExtensionDataReader:SetElement():this
         -14 (-37.84% of base) : System.Security.Cryptography.Csp.dasm - System.Security.Cryptography.PasswordDeriveBytes:Reset():this
         -42 (-37.17% of base) : System.Windows.Extensions.dasm - System.Media.SoundPlayer:CleanupStreamData():this
         -14 (-36.84% of base) : System.Data.OleDb.dasm - System.Data.OleDb.OleDbParameter:PropertyTypeChanging():this
         -35 (-36.46% of base) : System.Data.Common.dasm - System.Xml.XmlDataDocument:.ctor(System.Xml.XmlImplementation):this
         -21 (-36.21% of base) : System.Data.OleDb.dasm - System.Data.OleDb.OleDbParameter:ResetDbType():this
         -21 (-36.21% of base) : System.Data.OleDb.dasm - System.Data.OleDb.OleDbParameter:ResetOleDbType():this
         -61 (-35.47% of base) : System.Net.Requests.dasm - System.Net.CommandStream:InitCommandPipeline(System.Net.WebRequest,System.Net.CommandStream+PipelineEntry[],bool):this
         -75 (-35.21% of base) : System.Data.Odbc.dasm - System.Data.Odbc.OdbcParameter:CloneHelperCore(System.Data.Odbc.OdbcParameter):this
         -39 (-35.14% of base) : System.IO.FileSystem.dasm - System.IO.FileSystemInfo:Init(long):this
         -61 (-34.86% of base) : System.Private.DataContractSerialization.dasm - System.Xml.XmlBaseWriter:SetOutput(System.Xml.XmlStreamNodeWriter):this
         -42 (-33.33% of base) : System.Private.Xml.Linq.dasm - System.Xml.XPath.XNodeNavigator:.ctor(System.Xml.XPath.XNodeNavigator):this
         -66 (-32.51% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - Microsoft.Diagnostics.Tracing.UnhandledTraceEvent:.ctor():this
         -57 (-32.02% of base) : System.Private.DataContractSerialization.dasm - System.Xml.XmlBaseReader:MoveToComment():XmlCommentNode:this
         -57 (-32.02% of base) : System.Private.DataContractSerialization.dasm - System.Xml.XmlBaseReader:MoveToCData():XmlCDataNode:this
         -57 (-32.02% of base) : System.Private.DataContractSerialization.dasm - System.Xml.XmlBaseReader:MoveToComplexText():XmlComplexTextNode:this

Top method regressions (percentages):
          69 (14.56% of base) : CommandLine.dasm - CommandLine.Core.OptionSpecification:FromAttribute(CommandLine.OptionAttribute,System.Type,System.Collections.Generic.IEnumerable`1[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]):CommandLine.Core.OptionSpecification
         222 (13.65% of base) : Microsoft.CodeAnalysis.VisualBasic.dasm - Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.Parser:ParseFunctionOrSubLambdaHeader(byref,bool):Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.LambdaHeaderSyntax:this
          50 (13.16% of base) : System.Data.Common.dasm - System.Data.Index:GetUniqueKeyValues(System.Collections.Generic.List`1[[System.Object[], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]],int):this
          48 (13.04% of base) : System.Diagnostics.DiagnosticSource.dasm - System.Diagnostics.ActivityLink:GetHashCode():int:this
         224 (12.87% of base) : Microsoft.CodeAnalysis.VisualBasic.dasm - Microsoft.CodeAnalysis.VisualBasic.Symbols.SourceMemberContainerTypeSymbol:MakeExplicitInterfaceImplementationMap(Microsoft.CodeAnalysis.DiagnosticBag):System.Collections.Generic.Dictionary`2[[Microsoft.CodeAnalysis.VisualBasic.Symbol, Microsoft.CodeAnalysis.VisualBasic, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[Microsoft.CodeAnalysis.VisualBasic.Symbol, Microsoft.CodeAnalysis.VisualBasic, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]:this
         132 (12.37% of base) : Microsoft.CodeAnalysis.VisualBasic.dasm - Microsoft.CodeAnalysis.VisualBasic.UsingBlockBinder:BuildLocals():System.Collections.Immutable.ImmutableArray`1[[Microsoft.CodeAnalysis.VisualBasic.Symbols.LocalSymbol, Microsoft.CodeAnalysis.VisualBasic, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]:this
          97 (11.62% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - Microsoft.Diagnostics.Tracing.Stacks.TraceEventStackSource:LookupWarmSymbols(int,Microsoft.Diagnostics.Symbols.SymbolReader,Microsoft.Diagnostics.Tracing.Stacks.StackSource,System.Predicate`1[[Microsoft.Diagnostics.Tracing.Etlx.TraceModuleFile, Microsoft.Diagnostics.Tracing.TraceEvent, Version=2.0.49.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]):this
       
Top method improvements (bytes):
       -5527 (-18.45% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - Microsoft.Diagnostics.Tracing.Parsers.ClrTraceEventParser:EnumerateTemplates(System.Func`3[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.Diagnostics.Tracing.EventFilterResponse, Microsoft.Diagnostics.Tracing.TraceEvent, Version=2.0.49.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]],System.Action`1[[Microsoft.Diagnostics.Tracing.TraceEvent, Microsoft.Diagnostics.Tracing.TraceEvent, Version=2.0.49.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]):this
       -5355 (-16.50% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - Microsoft.Diagnostics.Tracing.Parsers.ClrPrivateTraceEventParser:EnumerateTemplates(System.Func`3[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.Diagnostics.Tracing.EventFilterResponse, Microsoft.Diagnostics.Tracing.TraceEvent, Version=2.0.49.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]],System.Action`1[[Microsoft.Diagnostics.Tracing.TraceEvent, Microsoft.Diagnostics.Tracing.TraceEvent, Version=2.0.49.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]):this
       -4258 (-9.37% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - Microsoft.Diagnostics.Tracing.Parsers.KernelTraceEventParser:EnumerateTemplates(System.Func`3[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.Diagnostics.Tracing.EventFilterResponse, Microsoft.Diagnostics.Tracing.TraceEvent, Version=2.0.49.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]],System.Action`1[[Microsoft.Diagnostics.Tracing.TraceEvent, Microsoft.Diagnostics.Tracing.TraceEvent, Version=2.0.49.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]):this
       -4054 (-20.70% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - Microsoft.Diagnostics.Tracing.Parsers.AspNet.AspNetTraceEventParser:EnumerateTemplates(System.Func`3[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.Diagnostics.Tracing.EventFilterResponse, Microsoft.Diagnostics.Tracing.TraceEvent, Version=2.0.49.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]],System.Action`1[[Microsoft.Diagnostics.Tracing.TraceEvent, Microsoft.Diagnostics.Tracing.TraceEvent, Version=2.0.49.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]):this
       -1764 (-28.59% of base) : System.Private.DataContractSerialization.dasm - System.Xml.XmlBinaryReader:ReadNode():bool:this
       -1485 (-7.85% of base) : System.Private.Xml.dasm - System.Xml.Xsl.IlGen.XmlILMethods:.cctor()
       -1417 (-20.96% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - Microsoft.Diagnostics.Tracing.Parsers.Clr.ClrRundownTraceEventParser:EnumerateTemplates(System.Func`3[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.Diagnostics.Tracing.EventFilterResponse, Microsoft.Diagnostics.Tracing.TraceEvent, Version=2.0.49.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]],System.Action`1[[Microsoft.Diagnostics.Tracing.TraceEvent, Microsoft.Diagnostics.Tracing.TraceEvent, Version=2.0.49.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]):this
       -1024 (-30.32% of base) : System.Private.Xml.dasm - System.Xml.Xsl.IlGen.XmlILTypeHelper:.cctor()
        -882 (-4.55% of base) : System.Text.RegularExpressions.dasm - System.Text.RegularExpressions.RegexCompiler:GenerateOneCode():this

rossgen CodeSize Diffs for benchstones and benchmarks game in D:\fxkit\runtime\artifacts\tests\coreclr\Windows_NT.x64.Checked for x64 default jit
Summary of Code Size diffs:
(Lower is better)
Total bytes of base: 357030
Total bytes of diff: 356449
Total bytes of delta: -581 (-0.16% of base)
    diff is an improvement.
Top file regressions (bytes):
          26 : Linq\Linq\Linq.dasm (0.13% of base)
          22 : BenchmarksGame\k-nucleotide\k-nucleotide-9\k-nucleotide-9.dasm (0.27% of base)
          12 : Serialization\Deserialize\Deserialize.dasm (0.51% of base)
          12 : BenchmarksGame\k-nucleotide\k-nucleotide-1\k-nucleotide-1.dasm (0.32% of base)
          12 : BenchmarksGame\reverse-complement\reverse-complement-6\reverse-complement-6.dasm (0.30% of base)
           6 : BenchmarksGame\binarytrees\binarytrees-5\binarytrees-5.dasm (0.31% of base)
Top file improvements (bytes):
        -347 : Bytemark\Bytemark\Bytemark.dasm (-0.46% of base)
        -167 : BenchmarksGame\pidigits\pidigits-3\pidigits-3.dasm (-4.68% of base)
        -125 : SIMD\RayTracer\RayTracer\RayTracer.dasm (-0.55% of base)
         -25 : BenchmarksGame\regex-redux\regex-redux-5\regex-redux-5.dasm (-0.79% of base)
          -4 : Roslyn\CscBench\CscBench.dasm (-0.13% of base)
          -3 : Span\Indexer\Indexer.dasm (-0.03% of base)
12 total files with Code Size differences (6 improved, 6 regressed), 70 unchanged.         

Top method improvements (bytes):
        -192 (-8.64% of base) : Bytemark\Bytemark\Bytemark.dasm - NeuralJagged:read_data_file():this
        -159 (-5.71% of base) : Bytemark\Bytemark\Bytemark.dasm - Neural:read_data_file():this
         -57 (-13.10% of base) : BenchmarksGame\pidigits\pidigits-3\pidigits-3.dasm - BenchmarksGame.pidigits:prdigit(int,bool):bool:this
         -55 (-5.95% of base) : BenchmarksGame\pidigits\pidigits-3\pidigits-3.dasm - BenchmarksGame.pidigits:compose_r(int,int,int,int):this
         -45 (-10.51% of base) : BenchmarksGame\pidigits\pidigits-3\pidigits-3.dasm - BenchmarksGame.pidigits:extract(int):int:this
         -45 (-12.57% of base) : SIMD\RayTracer\RayTracer\RayTracer.dasm - <Intersect>d__4:MoveNext():bool:this 

@briansull
Copy link
Contributor Author

@dotnet/jit-contrib PTAL

@briansull
Copy link
Contributor Author

Sample improvement:

image

@sandreenko sandreenko added the enhancement Product code improvement that does NOT require public API changes/additions label Sep 15, 2020
@AndyAyersMS
Copy link
Member

Nice improvement.

Non-crossgen diffs would be somewhat more relevant for perf... can you share those?

Does the allocator somehow know that these values don't need to be spilled?

@sandreenko
Copy link
Contributor

Fixes #41626?

@briansull
Copy link
Contributor Author

Does the allocator somehow know that these values don't need to be spilled?

These indirection are now correctly marked as invariant, so we know that their values can't be changed and we give the same value number and we create CSE's for the multiple reads. (when profitable)

I haven't examined the register allocator code, but it doesn't currently access the GTF_IND_INVARIANT flag.
It could as you suggest not spill (store) these values, when a simple IND(handle) cab be used for the reload.

@briansull
Copy link
Contributor Author

@sandreenko Yes This fixes #41626 and adds additional checking to insure that we always set these flags correctly going forwards.

@briansull
Copy link
Contributor Author

briansull commented Sep 15, 2020

Sample Regression:
This is a performance improvement as we hoist three indirections out of the loop.
This increase the number of registers that we save and restore by two and increases the codesize of the method.
However the PerfScore of the method improves (from 235.59 to 219.14) because the loop has fewer indirections (see IG09)

image
...
image
...
image

@briansull
Copy link
Contributor Author

briansull commented Sep 15, 2020

Other codesize regressions occur when we have new CSE's that require a callee saved register and when we enregister one (or more) of these new CSE, we then place several of the other LclVar into the stack frame which increase the overall code size.

Example:

image
...
image
...
image
...
image

@briansull
Copy link
Contributor Author

briansull commented Sep 16, 2020

@AndyAyersMS
Running the Benchmarks using PMI - I didn't get any diffs.
Looking at the Diffs that I did get without PMI shows that they were due to ReadyToRun indirections
Also Class handles and Method handles are embedded directly as constants and not fetched using an indirection with standard Jitted code, so these also don't show up with diffs in Jitted code.

@briansull
Copy link
Contributor Author

briansull commented Sep 16, 2020

Related issue:
dotnet/coreclr#14244

@briansull
Copy link
Contributor Author

briansull commented Sep 16, 2020

@AndyAyersMS

@briansull turns out we were not marking the embedded handle indirs as non-faulting.Good catch.
I also was going to mark them as invariant, but when doing so, CSE got carried away in places.

dotnet/coreclr#14244 (comment)

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

Overall this looks good but I have some questions I'd like you to address.

#define GTF_ICON_PSTR_HDL 0x70000000 // GT_CNS_INT -- constant is a ptr to a string handle
#define GTF_ICON_PTR_HDL 0x80000000 // GT_CNS_INT -- constant is a ldptr handle
#define GTF_ICON_CONST_PTR 0x70000000 // GT_CNS_INT -- constant is a pointer to immutable data, (e.g. IAT_PPVALUE)
#define GTF_ICON_PTR_GLOBAL 0x80000000 // GT_CNS_INT -- constant is a pointer to mutable data from the VM state
Copy link
Member

Choose a reason for hiding this comment

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

Nit: always put the _PTR suffix last?

Suggested change
#define GTF_ICON_PTR_GLOBAL 0x80000000 // GT_CNS_INT -- constant is a pointer to mutable data from the VM state
#define GTF_ICON_GLOBAL_PTR 0x80000000 // GT_CNS_INT -- constant is a pointer to mutable data from the VM state

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I will make those changes

@@ -7353,7 +7355,8 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT

var_types handleTyp = (var_types)(varTypeIsGC(lclTyp) ? TYP_BYREF : TYP_I_IMPL);
op1 = gtNewOperNode(GT_IND, handleTyp, op1);
op1->gtFlags |= GTF_IND_INVARIANT | GTF_IND_NONFAULTING;
op1->gtFlags |= GTF_IND_NONFAULTING;
noway_assert(!"Unreachable on CoreCLR");
Copy link
Member

Choose a reason for hiding this comment

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

If this is unreachable why not just remove it all together? We have already broken the ability to port the jit back to desktop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that this code path is only good for the desktop.
Instead it seems that the CoreCLR VM doesn't use this code path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add an assert and remove the unreachable block,
I found another section of code that asserted for the unreachable case.

op1->gtFlags |= GTF_IND_INVARIANT;
op1->gtFlags |= GTF_IND_NONFAULTING;

assert(!"Unreached GTF_IND_INVARIANT");
Copy link
Member

Choose a reason for hiding this comment

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

Ditto for this, if it's now unreachable, why not remove it all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add an assert and remove the unreachable block,

@@ -4488,10 +4495,20 @@ GenTree* Lowering::LowerNonvirtPinvokeCall(GenTreeCall* call)
break;

case IAT_PPVALUE:
// ToDo: Expanding an IAT_PPVALUE here, loses the opportunity
// to Hoist/CSE the first indirection as it is an invariant load
Copy link
Member

Choose a reason for hiding this comment

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

Are you going to open an issue for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would speed up PInkvoke calls that occur inside of a loop in a crossgen-ed assembly.
I will investigate how often this condition actually occurs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The following two methods in System.Private.Corelib have PInvoke calls inside of a loop:

Top method regressions (bytes):
          12 ( 3.74% of base) : System.Private.CoreLib.dasm - System.GC:GetTotalMemory(bool):long
           4 ( 0.35% of base) : System.Private.CoreLib.dasm - System.RuntimeType:GetInterfaceMap(System.Type):System.Reflection.InterfaceMapping:this

{
// Note that eGetCPString isn't currently implemented on Linux/ARM
// Note that eeGetCPString isn't currently implemented on Linux/ARM
Copy link
Member

Choose a reason for hiding this comment

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

Do we know why it's not implemented? Would it be simple to fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure how useful this EE method actually is
In my usage we rarely end up printing the actual string.
Currently it can't ever be printed at crossgen time, only at JIT time can we print the string.

Prior to my change we would try to print every string as the empty string
We get a null terminated string, and then print it as as ""

… are embedding a pointer to mutable data from the VM state
…stant is a pointer to immutable data, (e.g. IAT_PPVALUE)
… offset

In gtNewStringLiteralNode - Added assert for non-CoreRT case of a IAT_VALUE of a TYP_REF
… exits

as this can currently significantly limit our hoisting optimization.
…ctCall

and comment in Lowering::LowerNonvirtPinvokeCall where we currently allow this late expansion.
…f GTF_IND_INVARIANT

Disable the GTF_IND_INVARIANT for the cases that currentlt do not set it correctly.
…ugCheckFlags (disabled)

Minor changes with GTF_IND_NONFAULTING
Added assert(!"Check this")
Add check for GTF_ICON_PINVKI_HDL // Eventually remove, as this is immutable
Added  assert(!"Unreached GTF_IND_INVARIANT") in fgMorphField
Fixed IAT_PPVALUe and modified IAT_PVALUE cases in fgMorphLeaf for GT_FTN_ADDR
…rectly, set GTF_GLOB_REF for all class static indirections

Check that all class static indirections have GTF_GLOB_REF set
Changed two asserts to be noway_asserts
Changed the indirection that points to the array initialization blob to be a GTF_ICON_CONST_PTR instead of a GTF_ICON_STATIC_HDL.
Changed the indirection that fetches the field offset value for ReadyToRun to be a GTF_ICON_CONST_PTR instead of a GTF_ICON_FIELD_HDL.
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.

Nice change, LGTM.

Agree with Andy's review, I do not like assert(!"error message") blocks because it is not clear when we will be able to delete them in the future if we do not create an issue or TODO for them. So they are likely to be there forever once introduced.

//------------------------------------------------------------------------------
// fgDebugCheckDispFlags : Display the flags that we are checking
//
// Arguments:
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like the header was not finished.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will update this

// Expanding an IAT_PPVALUE here, will lose the opportunity
// to Hoist/CSE the first indirection as it is an invariant load
//
assert(!"IAT_PPVALUE case in LowerDirectCall");
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: How do we usually check such JIT expectations about VM return values? The current VM implementation (CEEInfo::getFunctionEntryPoint, ZapInfo::getFunctionEntryPoint) does not use IAT_PPVALUE, would it make sense to assert that pResult->accessType != IAT_PPVALUE in the VM code before we exit these functions and change this block to a unreached()?

Copy link
Contributor Author

@briansull briansull Sep 19, 2020

Choose a reason for hiding this comment

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

I don't believe that there is a hard and fast contract in this area.

The JIT is free to implement all possible variants and the VM is free to only utilize one or two and never use the third choice. When I noticed that waiting all the way until lower to materialize these indirections would not be optimal for codegen, I added the assert to find out if it was being used. It turns out in one case it was used and in another case it wasn't.

I don't think that this deserves an assert in the VM for this behavior. I like to reserve asserts for things that are actually incorrect in some semantic way. In any case if someone changes the VM and now asks for a double indirection we will get an assert in the JIT which is fine, because that is the component that has an issue with the double indirection case.

fieldMayOverlap ? FieldSeqStore::NotAField() : GetFieldSeqStore()->CreateSingleton(symHnd);
tree->AsClsVar()->gtFieldSeq = fieldSeq;
}
// We should always be able to access this static field address directly
Copy link
Member

@jkotas jkotas Sep 19, 2020

Choose a reason for hiding this comment

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

You can also delete ppIndirection argument of getFieldAddress method on JIT/EE interface if you are removing the JIT's ability to handle it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that we want to permanently want to remove this as a possibility from the JIt to EE interface.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that we want to permanently want to remove this as a possibility from the JIt to EE interface.

I agree with that, so why delete the code to handle it?

I am not convinced that this path is actually fully unreachable today. I won't be surprised if there is a way to hit this path in some cases under crossgen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are two JIT team members that asked for this code to be removed instead of having an assert that says it is unreached.

@briansull briansull merged commit 755f016 into dotnet:master Sep 21, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 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 enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants