Below example is taken from Microbenchmarks
public void ObjrefValueTypeObj()
{
for (int i = 0; i < InnerIterationCount200000; i++)
orvt = (FooORVT)o;
}
Here the only expression is an invariant inside the loop and can bring it outside and eliminate the loop. Instead we generate this on x64:
G_M64166_IG03:
48BA08581DBA14020000 mov rdx, 0x214BA1D5808
488B32 mov rsi, gword ptr [rdx]
48BA60D79AC3F77F0000 mov rdx, 0x7FF7C39AD760
483916 cmp qword ptr [rsi], rdx
7412 je SHORT G_M64166_IG05
;; bbWeight=4 PerfScore 22.00
G_M64166_IG04:
488BD6 mov rdx, rsi
48B960D79AC3F77F0000 mov rcx, 0x7FF7C39AD760
E870B392FF call CORINFO_HELP_UNBOX
;; bbWeight=1 PerfScore 1.50
G_M64166_IG05:
48B8E0571DBA14020000 mov rax, 0x214BA1D57E0
488B38 mov rdi, gword ptr [rax]
4883C708 add rdi, 8
4883C608 add rsi, 8
E886370A5F call CORINFO_HELP_ASSIGN_BYREF
E881370A5F call CORINFO_HELP_ASSIGN_BYREF
FFC3 inc ebx
3B1D5133DAFF cmp ebx, dword ptr [reloc classVar[0xc39ac8f8]]
7CA9 jl SHORT G_M64166_IG03
Below example is taken from Microbenchmarks
Here the only expression is an invariant inside the loop and can bring it outside and eliminate the loop. Instead we generate this on x64: