-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Optimize TimeSpan.FromX for constant input #55745
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
Conversation
|
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
|
@dotnet/jit-contrib PTAL at the change in importer.cpp |
src/coreclr/jit/importer.cpp
Outdated
| actualArg = gtFoldExprConst(actualArg); | ||
| } | ||
| } | ||
|
|
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.
Any reason we can't just call gtFoldExpr(actualArg) and catch some of the other cases where we can fold?
If you still want to case it out like this, I don't think any of these != nullptr checks are needed.
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.
there was some assert that checked actualArg's type against sigType. E.g. it failed for int -> ubyte (after gtFoldExpr)
* ADD int
+--* CNS_INT int 0
\--* FIELD ubyte hackishFieldName
\--* LCL_VAR ref V00 this
after gtFoldExpr:
* FIELD ubyte hackishFieldName
\--* LCL_VAR ref V00 this
I removed the assert and it seems work fine.
If you still want to case it out like this, I don't think any of these != nullptr checks are needed.
E.g. GT_HWINTRINSIC (Vector_get_Zero) is a binary node with both children nullptr (IsBinary returns true)
|
Also the |
Ah, right, I've just updated the diffs, these use correct baseline. |
|
@dotnet/jit-contrib @AndyAyersMS PTAL |
|
@dotnet/jit-contrib just going through old PR's that were already signed off and noticed this might possibly only need one review to merge. |
|
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsJust a small change to optimize TimeSpan Test() => TimeSpan.FromSeconds(5);Was: ; Method Program:Test():System.TimeSpan:this
4883EC28 sub rsp, 40
C5F877 vzeroupper
C5FB100511000000 vmovsd xmm0, qword ptr [reloc @RWD00]
E8A499FDFF call System.TimeSpan:IntervalFromDoubleTicks(double):System.TimeSpan
90 nop
4883C428 add rsp, 40
C3 ret
; Total bytes of code: 26Now: ; Method Program:Test():System.TimeSpan:this
B880F0FA02 mov eax, 0x2FAF080
C3 ret
; Total bytes of code: 6The JIT change caused some positive diffs in asm.libraries_tests.pmi.windows.x64.checked (because it triggered inlining in places where e.g. "cns op cns" expressions were not recognized as constant args): coreclr_tests.pmi.windows.x64.checked.mch:Detail diffslibraries.pmi.windows.x64.checked.mch:Detail diffslibraries_tests.pmi.windows.x64.checked.mch:Detail diffs
|
|
This PR optimized System.Tests.Perf_TimeSpan.FromSeconds but auto-filer didn't catch it, cc @DrewScoggins |
|
By default we exclude tests is they have an average less than .2ns. I cannot seem to find the discussion that we had about this, but maybe @tannergooding and @adamsitnik know where that is. Although after looking at the source code I did discover a bug, as we should file issues if we go from a value above .2ns to some value below it. I have fixed this issue. |

Just a small change to optimize
TimeSpan.FromXapis for constant input 🙂. I was just randomly inspecting various APIs when constant args are passed to find missing opportunities.Was:
Now:
The JIT change caused some positive diffs in asm.libraries_tests.pmi.windows.x64.checked (because it triggered inlining in places where e.g. "cns op cns" expressions were not recognized as constant args):
coreclr_tests.pmi.windows.x64.checked.mch:
Detail diffs
libraries.pmi.windows.x64.checked.mch:
Detail diffs
libraries_tests.pmi.windows.x64.checked.mch:
Detail diffs