-
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
Value array stack alloc alt #111284
Value array stack alloc alt #111284
Conversation
These flags are strictly optimizations. Having them required to be set for certain indirs based on context of the operand introduces IR invariants that are annoying to work with since it suddenly becomes necessary for all transformations to consider "did we just introduce this IR shape?". Instead, handle these patterns during morph as the optimization it is and remove the strict flags checking from `fgDebugCheckFlags`.
Leave the newarr helper call in place, and don't rewrite the uses to be uses of the local. Remove special handling in local morph and morph. Lower the helper to the proper stores later on. Update a few utilities to understand array base addresses may not be TYP_REF.
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
src/coreclr/jit/morph.cpp
Outdated
@@ -3660,7 +3633,7 @@ GenTree* Compiler::fgMorphIndexAddr(GenTreeIndexAddr* indexAddr) | |||
} | |||
|
|||
if (((index->gtFlags & (GTF_ASG | GTF_CALL | GTF_GLOB_REF)) != 0) || | |||
gtComplexityExceeds(index, MAX_INDEX_COMPLEXITY) || index->OperIs(GT_LCL_FLD) || | |||
gtComplexityExceeds(index, MAX_ARR_COMPLEXITY) || index->OperIs(GT_LCL_FLD) || |
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.
This line is a correctness fix. We were checking the index tree using the arr complexity.
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.
Ok, thanks. We should probably PR things like that separately.
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.
Guess it's not actually a functional change so no need for a separate PR
const int MAX_ARR_COMPLEXITY = 4;
const int MAX_INDEX_COMPLEXITY = 4;
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.
Yeah I think it's a copy-paste mistake.
I can't repro the x86 failure. Haven't looked into the R2R issues yet. |
One flaw with this approach is that the explicit zero inits are getting dead-coded by early liveness, because there are no evident uses of the array temp. We can fix this by using a custom new helper which takes the array address as an argument. And this introduces a dependence between the zero init and the new helper, which was absent before. That is, instead of the current
we produce
and (both) get later expanded to
The downside is we now have a jit helper with no runtime counterpart, which is a new concept, or we just tack on an extra arg to the existing helpers and hope it doesn't cause problems. |
This should show a decent set of SPMI diffs (though with 160ish misses in coreclr_tests we can remedy once we do yet another round of collection). Most of the diffs are now just extra prolog zeroing as the code shape in the method body is generally the same. Only rarely can we propagate through an array element, though I think we can improve on this some over time. I think it's in good shape and we should seriously consider it as the way forward. We can either use this PR or merge back into #104906. @hez2010, @jakobbotsch thoughts? |
For the R2R failures, it is failing on
This test seems to be checking what methods are inlineable across assembly boundaries, and evidently this method is now missing when it's expected to be in the allow list (I think the actual and expected labels are swapped here, the method is expected to be found in the list but isn't.) Need to dig into this further. When I looked at it earlier I couldn't figure out where things were going wrong. |
I'm seeing some regressions like this:
G_M59007_IG01: ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref, nogc <-- Prolog IG
- sub rsp, 40
+ sub rsp, 24
;; size=4 bbWeight=1 PerfScore 0.25
G_M59007_IG02: ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref
+ vxorps xmm0, xmm0, xmm0
+ vmovdqu xmmword ptr [rsp], xmm0
+ vmovdqu xmmword ptr [rsp+0x04], xmm0
+ mov rax, 0xD1FFAB1E ; <unknown class>
+ mov qword ptr [rsp], rax
+ mov dword ptr [rsp+0x08], 2
xor eax, eax
- ;; size=2 bbWeight=1 PerfScore 0.25
+ ;; size=39 bbWeight=1 PerfScore 4.83
G_M59007_IG03: ; bbWeight=1, epilog, nogc, extend
- add rsp, 40
+ add rsp, 24
ret It seems that we don't eliminate a dead stack allocated array. Is it expected? |
Yes, we will need some enhancements to detect cases like this. |
Pushed the changes over to #104906. So will close this. |
No description provided.