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
Fix method and basic block flags used by early opts. #2126
Conversation
Add missing BBF_HAS_NULLCHECK in loop test transformation. This change had no diffs in frameworks and benchmark. Add missing OMF_HAS_ARRAYREF and BBF_HAS_IDX_LEN in many places. This change had diffs in frameworks and benchmark since the optimization replacing GT_ARRLENGTH with a constant fires much more often. Fix inlining to not lose basic block flags when the inlinee basic block has a ret expr but no statements. Change propGetType condition in optDoEarlyPropForFunc to check for OMF_HAS_NEWARRAY in addition to OMF_HAS_NEWOBJ. Check that methods and basic blocks that have calls to object allocation helpers have OMF_HAS_NEWOBJ and BBF_HAS_NEWOBJ set. Check that methods and basic blocks that have calls to array allocation helpers have OMF_HAS_NEWARRAY and BBF_HAS_NEWARRAY set. Check that methods and basic blocks that have GT_NULLCHECK nodes helpers have OMF_HAS_NULLCHECK and BBF_HAS_NULLCHECK set. Check that methods and basic blocks that access MethodTable via GT_IND on a ref have OMF_HAS_VTABLEREF and BBF_HAS_VTABLEREF set. Check that methods and basic blocks that have GT_ARRLENGTH have OMF_HAS_ARRAYREF and BBF_HAS_IDX_LEN set.
x64 pmi benchmark diffs:
|
x64 pmi framework diffs:
|
Regressions in all methods except In -mov rax, gword ptr [rsp+38H]
-cmp dword ptr [rax+8], 4
-setge r9b
-movzx r9, r9b
-test r8d, r9d
+test r8b, 1
The successor basic blocks need
|
In good diffs sometimes we can avoid loop cloning because after we've replaced ; Assembly listing for method IniArray:Bench():bool
; Emitting BLENDED_CODE for X64 CPU with AVX - Windows
; optimized code
; rsp based frame
; fully interruptible
; Final local variable assignments
;
-; V00 loc0 [V00,T01] ( 5, 38 ) ref -> rax class-hnd exact
+; V00 loc0 [V00,T01] ( 3, 18 ) ref -> rax class-hnd exact
; V01 loc1 [V01,T02] ( 4, 13 ) int -> rdx
-; V02 loc2 [V02,T00] ( 9,132 ) int -> rcx
+; V02 loc2 [V02,T00] ( 5, 68 ) int -> rcx
; V03 OutArgs [V03 ] ( 1, 1 ) lclBlk (32) [rsp+0x00] "OutgoingArgSpace"
;
; Lcl frame size = 40
G_M27841_IG01:
sub rsp, 40
G_M27841_IG02:
mov rcx, 0xD1FFAB1E
mov edx, 16
call CORINFO_HELP_NEWARR_1_VC
xor edx, edx
G_M27841_IG03:
xor ecx, ecx
- cmp dword ptr [rax+8], 16
- jl SHORT G_M27841_IG06
G_M27841_IG04:
movsxd r8, ecx
mov word ptr [rax+2*r8+16], 32
inc ecx
cmp ecx, 16
jl SHORT G_M27841_IG04
G_M27841_IG05:
- jmp SHORT G_M27841_IG07
+ inc edx
+ cmp edx, 0xD1FFAB1E
+ jl SHORT G_M27841_IG03
G_M27841_IG06:
- movsxd r8, ecx
- mov word ptr [rax+2*r8+16], 32
- inc ecx
- cmp ecx, 16
- jl SHORT G_M27841_IG06
+ mov rcx, 0xD1FFAB1E
+ mov rdx, rax
+ call CORINFO_HELP_CHECKED_ASSIGN_REF
+ mov eax, 1
G_M27841_IG07:
- inc edx
- cmp edx, 0xD1FFAB1E
- jl SHORT G_M27841_IG03
-G_M27841_IG08:
- mov rcx, 0xD1FFAB1E
- mov rdx, rax
- call CORINFO_HELP_CHECKED_ASSIGN_REF
- mov eax, 1
-G_M27841_IG09:
add rsp, 40
ret
-; Total bytes of code 110, prolog size 4, PerfScore 131.00, (MethodHash=1c8e933f) for method IniArray:Bench():bool
+; Total bytes of code 84, prolog size 4, PerfScore 64.40, (MethodHash=1c8e933f) for method IniArray:Bench():bool
|
@dotnet/jit-contrib @AndyAyersMS PTAL |
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.
Looks good overall, just one question...
src/coreclr/src/jit/earlyprop.cpp Outdated
@@ -18,18 +18,26 @@ | |||
bool Compiler::optDoEarlyPropForFunc() | |||
{ | |||
#if DEBUG | |||
return true; |
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.
I worry a little about this. I take it you're relying on the fact that any missing flag in debug/check build will lead to assert, so the fact that debug/check potentially diverges from release is ok.
But if the flag checking somehow misses a case....
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.
I pushed a change where I added asserts right before we do transformations to make sure we'll get there in release as well. Does that address your concern?
I also fixed one more place where we were losing basic block flags. That was causing an assert in arm64 test run.
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.
I pushed one more change. I noticed that BBF_HAS_VTABREF was missing in BBF_COMPACT_UPD and BBF_SPLIT_GAINED so I added it. This wasn't caught by asserts and doesn't produce any new diffs.
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.
The run before the last commit was green. I think this is ready for another review. @AndyAyersMS PTAL.
Add asserts to make sure we don't have diverging codegen in debug/checked/release because of early opts.
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.
Latest version looks good.
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.
LGTM
Add missing BBF_HAS_NULLCHECK in loop test transformation.
This change had no diffs in frameworks and benchmark.
Add missing OMF_HAS_ARRAYREF and BBF_HAS_IDX_LEN in many places.
This change had diffs in frameworks and benchmark since the optimization
replacing GT_ARRLENGTH with a constant fires much more often.
Fix inlining to not lose basic block flags when the inlinee basic block
has a ret expr but no statements.
Change propGetType condition in optDoEarlyPropForFunc to check for OMF_HAS_NEWARRAY
in addition to OMF_HAS_NEWOBJ.
Check that methods and basic blocks that have calls to object allocation
helpers have OMF_HAS_NEWOBJ and BBF_HAS_NEWOBJ set.
Check that methods and basic blocks that have calls to array allocation
helpers have OMF_HAS_NEWARRAY and BBF_HAS_NEWARRAY set.
Check that methods and basic blocks that have GT_NULLCHECK nodes
helpers have OMF_HAS_NULLCHECK and BBF_HAS_NULLCHECK set.
Check that methods and basic blocks that access MethodTable
via GT_IND on a ref have OMF_HAS_VTABLEREF and BBF_HAS_VTABLEREF set.
Check that methods and basic blocks that have GT_ARRLENGTH
have OMF_HAS_ARRAYREF and BBF_HAS_IDX_LEN set.