Uh oh!
There was an error while loading. Please reload this page.
JIT: import static readonly fields holding frozen objects as const handles - #76112
Conversation
ghost
commented
Sep 24, 2022
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsJIT is able to fold staticstringMyStr{get;}= "Hello";
staticreadonlyTypes_type=typeof(int);staticvoidFoo(){Console.WriteLine(MyStr);Console.WriteLine(s_type);}Tier1 codegen diff for ; Assembly listing for method Foo()
; Tier-1 compilation
G_M14074_IG01: 4883EC28 sub rsp, 40
G_M14074_IG02: - 48B9C01EC0CB9E020000 mov rcx, 0x29ECBC01EC0 ; const ptr- 488B09 mov rcx, gword ptr [rcx]+ 48B9B017954DDA010000 mov rcx, 0x1DA4D9517B0 ; 'Hello'
FF15B9073800 call [System.Console:WriteLine(System.String)]
- 48B9C81EC0CB9E020000 mov rcx, 0x29ECBC01EC8 ; const ptr- 488B09 mov rcx, gword ptr [rcx]+ 48B9D017954DDA010000 mov rcx, 0x1DA4D9517D0 ; 'System.Int32'
FF158E073800 call [System.Console:WriteLine(System.Object)]
90 nop G_M14074_IG03: 4883C428 add rsp, 40
C3 ret Motivation
Jit-diffPR is verbose due to JIT-EE update, the actual changes are fairly small.
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jkotas
commented
Sep 24, 2022
BTW: Storing frozen objects does not require write barrier. For example: Does this optimization happen already? If not, we just need to skip the write barrier for frozen icon handles, similar how we skip them for nulls. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
EgorBo
commented
Sep 24, 2022
Good point! Do you mind if I do it separately, I also wanted to e.g. check if it's worth optimizing pinning against frozen objects, etc. Separate commits also help to triage perf improvements/regressions |
jkotas
commented
Sep 24, 2022
Yes, it is fine to do it separately. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Uh oh!
There was an error while loading. Please reload this page.
…pl.RyuJit.cs Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Uh oh!
There was an error while loading. Please reload this page.
EgorBo
commented
Oct 8, 2022
Looks like |
jkotas
commented
Oct 8, 2022
Sounds reasonable. |
EgorBo
commented
Oct 10, 2022
CI is green except SPMI jobs (JIT-EE change), going to merge |
JIT is able to fold
static readonlyfields to constants for primitive types. This PR extends that to handle such fields pointing to frozen objects, example:Tier1 codegen diff for
Foo:UPD: Also, this PR helps NativeAOT:
see #76112 (comment) thread
Motivation
static readonly Type .* = typeofpattern found 211 matches in dotnet/runtime (tests are not included)Example: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.Cache.cs#L15-L18
static readonly string .* = "\w+";found 119 results in dotnet/runtime (tests are not included)Array.Empty<T>as was suggested by @jkotasJit-diff (
-f --pmi --cctors)Regressions seem to be CSE related e.g. https://www.diffchecker.com/E3PieJCB + changed inlining decisions due to changes in gtGetClassHandle
PR is verbose due to JIT-EE update, the actual changes are fairly small.