Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4704,6 +4704,28 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
}
}

// Try to load handle directly for known types
if (retNode == nullptr)
{
GenTree* tree = impStackTop().val;
bool isExact = false;
bool notNull = false;
CORINFO_CLASS_HANDLE typeHnd = gtGetClassHandle(tree, &isExact, &notNull);
if ((typeHnd != NO_CLASS_HANDLE) && isExact)
{
assert((info.compCompHnd->getClassAttribs(typeHnd) & CORINFO_FLG_GENERIC_TYPE_VARIABLE) == 0);
if (!eeIsSharedInst(typeHnd) && notNull && !fgAddrCouldBeNull(tree))
{
JITDUMP("Optimizing object.GetType() with known type to typeof\n");
impPopStack();
GenTree* handle = gtNewIconEmbClsHndNode(typeHnd);
GenTree* helper =
gtNewHelperCallNode(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE, TYP_REF, handle);
retNode = gtWrapWithSideEffects(helper, tree, GTF_ALL_EFFECT, true);
}
}
}

#ifdef DEBUG
if (retNode != nullptr)
{
Expand Down
Loading