Description
usingSystem.Runtime.CompilerServices;[MethodImpl(MethodImplOptions.AggressiveInlining)]byteCreate<T>(Tvalue){returnUnsafe.As<T,byte>(refvalue);}Console.WriteLine(Create(500));Console.WriteLine(Create(500L));JIT dump:
mov dword ptr [rsp+0x44],0x1f4movzxecx, byte ptr [rsp+0x44]call System.Console.WriteLine(Int32)mov qword ptr [rsp+0x38],0x1f4movzxecx, byte ptr [rsp+0x38]call System.Console.WriteLine(Int32)
I think the ref can be omitted so that value won't be spilled to stack,
which is expected to be (on a little endian system):
movecx,0xf4call System.Console.WriteLine(Int32)movecx,0xf4call System.Console.WriteLine(Int32)
Configuration
Version: .NET 6 preview 5
Tiered Compilation: off
category:cq
theme:codegen
skill-level:intermediate
cost:small
impact:medium
Description
JIT dump:
I think the
refcan be omitted so thatvaluewon't be spilled to stack,which is expected to be (on a little endian system):
Configuration
Version: .NET 6 preview 5
Tiered Compilation: off
category:cq
theme:codegen
skill-level:intermediate
cost:small
impact:medium