Optimize new DateTime(const, const, const)#64612
Closed
EgorBo wants to merge 4 commits into
Closed
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsThis PR optimizes [Benchmark]
public DateTime ConstDate() => new (2022, 12, 10);Currently emits: ; Method Test:ConstDate():System.DateTime:this
G_M10442_IG01: ;; offset=0000H
4883EC28 sub rsp, 40
G_M10442_IG02: ;; offset=0004H
48B9104AD1CEF87F0000 mov rcx, 0x7FF8CED14A10
BAF9000000 mov edx, 249
E808639F5F call CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE
48B8201280B98B020000 mov rax, 0x28BB9801220
488B00 mov rax, gword ptr [rax]
8B5008 mov edx, dword ptr [rax+8]
83FA0C cmp edx, 12
762B jbe SHORT G_M10442_IG05
8B5040 mov edx, dword ptr [rax+64]
8B403C mov eax, dword ptr [rax+60]
2BD0 sub edx, eax
83FA0A cmp edx, 10
7218 jb SHORT G_M10442_IG04
0574430B00 add eax, 0xB4374
48BA00C0692AC9000000 mov rdx, 0xC92A69C000
480FAFC2 imul rax, rdx
G_M10442_IG03: ;; offset=004DH
4883C428 add rsp, 40
C3 ret
G_M10442_IG04: ;; offset=0052H
E8B183FFFF call System.ThrowHelper:ThrowArgumentOutOfRange_BadYearMonthDay()
CC int3
G_M10442_IG05: ;; offset=0058H
E803AD685F call CORINFO_HELP_RNGCHKFAIL
CC int3
; Total bytes of code: 94New codegen: ; Method Test:ConstDate():System.DateTime:this
G_M10442_IG01: ;; offset=0000H
G_M10442_IG02: ;; offset=0000H
48B80040044BBAE2D908 mov rax, 0x8D9E2BA4B044000
G_M10442_IG03: ;; offset=000AH
C3 ret
; Total bytes of code: 11Benchmarks
Feel free to reject it 🙂, eventually we should be able to get constant case codegen even with the current code, for that we need:
|
Member
Author
|
Closing as it's unlikely the hack worth it or people use this pattern on hot paths, but it should be a good challenge for jit to do everything under the hood. Another note that my single line change in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR optimizes
new DateTime(const, const, const)case, e.g.:Currently emits:
New codegen:
Benchmarks
Feel free to reject it 🙂, eventually we should be able to get constant case codegen even with the current code, for that we need:
ReadOnlySpan<any primitive>for RVA datas_daysToMonth365ands_daysToMonth366ReadOnlySpan<uint>RVA[const index]folding in JIT - unfortunately it's a bit tricky but should be doable