-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Profiled casts: isinst is no longer hoisted #96837
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsSince we expand a lot more casts now, we hit more cases where expanded (early) cast becomes non-hoistable, example: [MethodImpl(MethodImplOptions.NoInlining)]
bool foo(object o)
{
bool result = false;
for (int i = 0; i < 100000; i++)
result = o is IDisposable; // o is "mostly" Program instance in my benchmark
return result;
} Codegen with G_M31828_IG01: ;; offset=0x0000
push rbx
sub rsp, 32
G_M31828_IG02: ;; offset=0x0005
xor ebx, ebx
mov rcx, 0x7FF80DB09C28 ; System.IDisposable
call CORINFO_HELP_ISINSTANCEOFINTERFACE
test rax, rax
setne al
movzx rax, al
jmp SHORT G_M31828_IG03
align [0 bytes for IG03]
G_M31828_IG03: ;; offset=0x0021
mov ecx, eax
inc ebx
cmp ebx, 0x186A0
jl SHORT G_M31828_IG03
G_M31828_IG04: ;; offset=0x002D
mov eax, ecx
G_M31828_IG05: ;; offset=0x002F
add rsp, 32
pop rbx
ret Codegen with G_M31828_IG01: ;; offset=0x0000
push rsi
push rbx
sub rsp, 40
mov rbx, rdx
G_M31828_IG02: ;; offset=0x0009
xor esi, esi
G_M31828_IG03: ;; offset=0x000B
mov rax, rbx
test rax, rax
je SHORT G_M31828_IG06
G_M31828_IG04: ;; offset=0x0013
mov rdx, 0x7FF80DDE0988 ; Program
cmp qword ptr [rax], rdx
je SHORT G_M31828_IG06
G_M31828_IG05: ;; offset=0x0022
mov rdx, rbx
mov rcx, 0x7FF80DAF9C28 ; System.IDisposable
call CORINFO_HELP_ISINSTANCEOFINTERFACE
G_M31828_IG06: ;; offset=0x0034
test rax, rax
setne al
movzx rax, al
inc esi
cmp esi, 0x186A0
jl SHORT G_M31828_IG03
G_M31828_IG07: ;; offset=0x0047
add rsp, 40
pop rbx
pop rsi
ret
|
Do you mean hoisting? |
Is CSE able to clean it up if you peel one iteration of the loop manually? |
No, clonning
Nope 😢 or I am doing it wrong |
Ah yeah, I guess the extra control flow makes us unable to handle it by CSE and makes it not really feasible to improve hoisting to handle it too, hmmpf. This is sort of the "hammock" concept that @AndyAyersMS talks about sometimes, I think, where multiple blocks of the flow graph can/should be considered as one atomic thing. |
Since we expand a lot more casts now, we hit more cases where expanded (early) cast becomes non-hoistable, example:
Codegen with
DOTNET_JitProfileCasts=0
:Codegen with
DOTNET_JitProfileCasts=1
:Options:
isinst
if it's inisde a loop (backward branch) - the easiest and the most conservative option.castclass
is fine, we don't hoist it due to side-effects anyway.The text was updated successfully, but these errors were encountered: