-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fold 'static readonly struct' to constants #77102
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue Detailsstatic readonly DateTime date = DateTime.Now;
DateTime Test() => date; Codegen diff: ; Assembly listing for method Program:Test():System.DateTime:this
- 48B8C01E00DAC1010000 mov rax, 0x1C1DA001EC0
- 488B00 mov rax, gword ptr [rax]
- 488B4008 mov rax, qword ptr [rax+08H]
+ 48B8F0BCFF19B4AFDA88 mov rax, 0x88DAAFB419FFBCF0
C3 ret
-; Total bytes of code 18
+; Total bytes of code 11
|
41d2ffa
to
432cf04
Compare
What kind of structs are supported? Single-fields only? |
With the current impl up to 4 fields of primitive types |
@EgorBo does this mean that Guid is out of the equation? It's layout is quite complex but I think comparisons with Guid.Empty are quite common |
Yes, I plan to play with guid separately |
@dotnet/jit-contrib PTAL, I limited it to single-field structs for now to avoid unexpected regressions due to promotions and since mostly TimeSpan/DateTime/TimeOnly/DateOnly/DateTimeOffset benefit from this which are single-field structs. I plan to play with it in on VN-level and with larger structs such as Guid in future PRs. |
This works for NativeAOT as well, although, |
Not close to computers these days but pretty sure DateTime is not preinitialized because of leap seconds support stuff that does pinvokes and can't be interpreted at compile time. We would have to factor that out to a spearate cctor or something. |
@AndyAyersMS @jakobbotsch PTAL |
/azp run runtime-coreclr jitstress, runtime-coreclr outerloop, Fuzzlyn |
Azure Pipelines successfully started running 3 pipeline(s). |
|
Co-authored-by: Andy Ayers <andya@microsoft.com>
…into static-readonly-struct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reworking all this into impImportStaticReadOnlyField
.
Codegen diff:
jit-diffs (
-f --pmi --cctors
):