Repository navigation
Avoid boxing in Enum.HasFlag in Tier0 - #89348
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsWe see a lot of cases when methods stay in Tier0 despite being called a lot in large apps (the "tier1 promotion queue" problem) so we'd better remove allocations in Tier0 too where possible, I gave up on this opt in #77357 but I still think it's useful: bool Test(MyEnum e) => e.HasFlag(MyEnum.B);Main: ; Assembly listing for method Program:Test(int):bool (Tier0)
push rbp
sub rsp, 48
lea rbp, [rsp+30H]
xor eax, eax
mov qword ptr [rbp-08H], rax
mov qword ptr [rbp-10H], rax
mov dword ptr [rbp+10H], ecx
mov rcx, 0x7FFAE2C3B208
call CORINFO_HELP_NEWSFAST ;; <--- Allocation
mov gword ptr [rbp-08H], rax
mov rcx, gword ptr [rbp-08H]
mov eax, dword ptr [rbp+10H]
mov dword ptr [rcx+08H], eax
mov rcx, 0x7FFAE2C3B208
call CORINFO_HELP_NEWSFAST ;; <--- Allocation
mov gword ptr [rbp-10H], rax
mov rcx, gword ptr [rbp-10H]
mov dword ptr [rcx+08H], 1
mov rcx, gword ptr [rbp-08H]
mov rdx, gword ptr [rbp-10H]
call [System.Enum:HasFlag(System.Enum):bool:this]
nop
add rsp, 48
pop rbp
ret
; Total bytes of code 103PR: ; Assembly listing for method Program:Test(int):bool (Tier0)
push rbp
sub rsp, 32
lea rbp, [rsp+20H]
xor eax, eax
mov qword ptr [rbp-08H], rax
mov qword ptr [rbp-10H], rax
mov dword ptr [rbp+10H], ecx
mov eax, dword ptr [rbp+10H]
mov dword ptr [rbp-14H], eax
mov eax, dword ptr [rbp-14H]
and eax, 1
cmp eax, 1
sete al
movzx rax, al
add rsp, 32
pop rbp
ret
; Total bytes of code 50
|
|
@MihuBot -tier0 |
|
@dotnet/jit-contrib PTAL, simple change - no SPMI diffs (new contexts), jit-diffs in tier0: |
Co-authored-by: Michał Petryka <[email protected]>
|
@jakobbotsch @dotnet/jit-contrib PTAL, simple change Should fix the concerns raised in AvaloniaUI/Avalonia#4873 (comment) |
Co-authored-by: Jakob Botsch Nielsen <[email protected]>
|
Acutally, I don't think we need to guard this under debug/minopts - it won't decrease quality of debug. Maybe we shouldn't share them for debug/minopts at all |
Presumably there is a reason the code exists in the first place. It would be good to verify the original scenarios that caused the code to be added do not get regressed with these changes. Also cc @AndyAyersMS |
jakobbotsch
left a comment
There was a problem hiding this comment.
Looks good to me with the above note -- it would be nice to double check whether there were some particular programs that caused this sharing to be added in the first place.
Would also like to hear @AndyAyersMS's opinion.
|
/azp run runtime-coreclr superpmi-diffs |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Seems like there are build failures. |
Oops, fixed.
I wonder if sharing actually makes debug experience worse. |
|
I don't believe there is any impact on debugging as the box temp is always a (evaluation) stack object. I think the sharing bit is from way back; I always thought it was there to avoid some code size / frame bloat. If you disable sharing entirely presumably you might see some of this in SPMI. |
We see a lot of cases when methods stay in Tier0 despite being called a lot in large apps (the "tier1 promotion queue" problem) so we'd better remove allocations in Tier0 too where possible, I gave up on this opt in #77357 but I still think it's useful:
Main (Tier0):
PR (Tier0):