Description
Repro:
class Program
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static nint Test<T>()
{
var type = typeof(T);
var handle = type.TypeHandle;
if (type.IsValueType)
{
return handle.Value;
}
return -1;
}
public static void Main()
{
var v1 = Test<int>(); ;
var v2 = Test<string>();
Console.WriteLine(v1 + v2);
}
}
Codegen for Main:
; Method Program:Main()
G_M27646_IG01: ;; offset=0000H
push rsi
sub rsp, 32
;; size=5 bbWeight=1 PerfScore 1.25
G_M27646_IG02: ;; offset=0005H
mov rcx, 0x1C980204A88 ; 'System.Int32'
cmp dword ptr [rcx], ecx
call [System.RuntimeType:IsValueTypeImpl():bool:this]
test eax, eax
je SHORT G_M27646_IG04
;; size=22 bbWeight=1 PerfScore 7.50
G_M27646_IG03: ;; offset=001BH
mov rsi, 0x7FFCA727E7E8
jmp SHORT G_M27646_IG05
;; size=12 bbWeight=0.50 PerfScore 1.12
G_M27646_IG04: ;; offset=0027H
mov rsi, -1
;; size=10 bbWeight=0.50 PerfScore 0.12
G_M27646_IG05: ;; offset=0031H
mov rcx, 0x1C9802000B8 ; 'System.String'
cmp dword ptr [rcx], ecx
call [System.RuntimeType:IsValueTypeImpl():bool:this]
test eax, eax
je SHORT G_M27646_IG07
;; size=22 bbWeight=1 PerfScore 7.50
G_M27646_IG06: ;; offset=0047H
mov rcx, 0x7FFCA7406F38
jmp SHORT G_M27646_IG08
;; size=12 bbWeight=0.50 PerfScore 1.12
G_M27646_IG07: ;; offset=0053H
mov rcx, -1
;; size=10 bbWeight=0.50 PerfScore 0.12
G_M27646_IG08: ;; offset=005DH
add rcx, rsi
call [System.Console:WriteLine(long)]
nop
;; size=10 bbWeight=1 PerfScore 3.50
G_M27646_IG09: ;; offset=0067H
add rsp, 32
pop rsi
ret
;; size=6 bbWeight=1 PerfScore 1.75
; Total bytes of code: 109
But if I change the code to:
class Program
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static nint Test<T>()
{
var type = typeof(T);
var handle = type.TypeHandle;
if (typeof(T).IsValueType)
{
return handle.Value;
}
return -1;
}
public static void Main()
{
var v1 = Test<int>(); ;
var v2 = Test<string>();
Console.WriteLine(v1 + v2);
}
}
The codegen will be expected:
; Method Program:Main()
G_M27646_IG01: ;; offset=0000H
sub rsp, 40
;; size=4 bbWeight=1 PerfScore 0.25
G_M27646_IG02: ;; offset=0004H
mov rcx, 0x7FFCB20FE7E7
call [System.Console:WriteLine(long)]
nop
;; size=17 bbWeight=1 PerfScore 3.50
G_M27646_IG03: ;; offset=0015H
add rsp, 40
ret
;; size=5 bbWeight=1 PerfScore 1.25
; Total bytes of code: 26
Description
Repro:
Codegen for
Main:But if I change the code to:
The codegen will be expected: