-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Description
int Test<T>(T obj)
{
if (obj is int x)
return x;
return 0;
}For int as T I expect this method to be just return obj, but instead I see:
L0000: push rsi
L0001: sub rsp, 0x20
L0005: mov esi, ecx
L0007: mov rcx, 0x7ffec353b1e8
L0011: call 0x7fff23084690
L0016: mov [rax+0x8], esi
L0019: mov eax, [rax+0x8]
L001c: add rsp, 0x20
L0020: pop rsi
L0021: retsee sharplab.io
JIT already optimizes some patterns, e.g.
box
isinst
brtrue
but it doesn't optimize this (correct me if I am wrong)
box
isinst
unbox.any
See
runtime/src/coreclr/src/jit/importer.cpp
Lines 5904 to 5915 in 5c9338e
| case CEE_ISINST: | |
| // box + isinst + br_true/false | |
| if (codeAddr + 1 + sizeof(mdToken) + 1 <= codeEndp) | |
| { | |
| const BYTE* nextCodeAddr = codeAddr + 1 + sizeof(mdToken); | |
| switch (nextCodeAddr[0]) | |
| { | |
| case CEE_BRTRUE: | |
| case CEE_BRTRUE_S: | |
| case CEE_BRFALSE: | |
| case CEE_BRFALSE_S: |
CEE_UNBOX_ANY)Reactions are currently unavailable
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