-
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
Noticed in #84370 (comment)
public class ClassA
{
public virtual int GetVal() => 1;
}
public sealed class ClassB : ClassA
{
public override int GetVal() => 42;
}
void GetValUnsafe(ClassA tc) => Unsafe.As<ClassB>(tc).GetVal();
Current codegen:
; Method GetValUnsafe(ClassA):this
sub rsp, 40
mov rcx, rdx
mov rax, qword ptr [rdx]
mov rax, qword ptr [rax+48H]
call [rax+20H]ClassA:GetVal():int:this
nop
add rsp, 40
ret
; Total bytes of code: 23
Expected codegen:
; Method GetValUnsafe(ClassB):this
cmp byte ptr [rdx], dl
ret
; Total bytes of code: 3
The idea that Unsafe.As JIT intrinsic should spill its input to a local and set class for that local based on signature.
runtime/src/coreclr/jit/importercalls.cpp
Lines 3977 to 3985 in 042a350
case NI_SRCS_UNSAFE_As: | |
{ | |
assert((sig->sigInst.methInstCount == 1) || (sig->sigInst.methInstCount == 2)); | |
// ldarg.0 | |
// ret | |
return impPopStack().val; | |
} |
MihaZupan and neon-sunsetGrabYourPitchforks, rameel, saucecontrol, PaulusParssinen and Sergio0694
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