-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone
Description
Since 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 DOTNET_JitProfileCasts=0:
G_M31828_IG01:
push rbx
sub rsp, 32
G_M31828_IG02:
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]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; <loop_start>
G_M31828_IG03:
mov ecx, eax
inc ebx
cmp ebx, 0x186A0
jl SHORT G_M31828_IG03
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; <loop_end>
G_M31828_IG04:
mov eax, ecx
G_M31828_IG05:
add rsp, 32
pop rbx
retCodegen with DOTNET_JitProfileCasts=1:
G_M31828_IG01:
push rsi
push rbx
sub rsp, 40
mov rbx, rdx
G_M31828_IG02:
xor esi, esi
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; <loop_start>
G_M31828_IG03:
mov rax, rbx
test rax, rax
je SHORT G_M31828_IG06
G_M31828_IG04:
mov rdx, 0x7FF80DDE0988 ; Program
cmp qword ptr [rax], rdx
je SHORT G_M31828_IG06
G_M31828_IG05:
mov rdx, rbx
mov rcx, 0x7FF80DAF9C28 ; System.IDisposable
call CORINFO_HELP_ISINSTANCEOFINTERFACE
G_M31828_IG06:
test rax, rax
setne al
movzx rax, al
inc esi
cmp esi, 0x186A0
jl SHORT G_M31828_IG03
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; <loop_end>
G_M31828_IG07:
add rsp, 40
pop rbx
pop rsi
retOptions:
- Don't instrument
isinstif it's inisde a loop (backward branch) - the easiest and the most conservative option. - Expand all casts in a late phase - we might miss some branch opts
- Extend loop clonning
castclass is fine, we don't hoist it due to side-effects anyway.
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI