Skip to content
Merged
Changes from 7 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
24 changes: 18 additions & 6 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12416,7 +12416,8 @@ GenTree* Compiler::impCastClassOrIsInstToTree(
bool partialExpand = false;
const CorInfoHelpFunc helper = info.compCompHnd->getCastingHelper(pResolvedToken, isCastClass);

GenTree* exactCls = nullptr;
GenTree* exactCls = nullptr;
bool isExpandingArray = false;

// Legality check.
//
Expand All @@ -12429,12 +12430,23 @@ GenTree* Compiler::impCastClassOrIsInstToTree(
// Jit can only inline expand the normal CHKCASTCLASS helper.
canExpandInline = (helper == CORINFO_HELP_CHKCASTCLASS);
}
else
else if (helper == CORINFO_HELP_ISINSTANCEOFCLASS)
{
if (helper == CORINFO_HELP_ISINSTANCEOFCLASS)
// If the class is exact, the jit can expand the IsInst check inline.
canExpandInline = isClassExact;
}

if (isClassExact && ((helper == CORINFO_HELP_ISINSTANCEOFARRAY) || (helper == CORINFO_HELP_CHKCASTARRAY)))
{
// We have "obj isinst/castclass T[]" and in case if T is sealed we can still perform
// the fast pMT check (in case if T[] -> obj.GetType is legal in jit-time)

CORINFO_CLASS_HANDLE elementCls = NO_CLASS_HANDLE;
info.compCompHnd->getChildType(pResolvedToken->hClass, &elementCls);
if ((elementCls != NO_CLASS_HANDLE) && impIsClassExact(elementCls))
{
// If the class is exact, the jit can expand the IsInst check inline.
canExpandInline = isClassExact;
canExpandInline = true;
isExpandingArray = true;
}
}

Expand Down Expand Up @@ -12565,7 +12577,7 @@ GenTree* Compiler::impCastClassOrIsInstToTree(
//
// use the special helper that skips the cases checked by our inlined cast
//
const CorInfoHelpFunc specialHelper = CORINFO_HELP_CHKCASTCLASS_SPECIAL;
const CorInfoHelpFunc specialHelper = isExpandingArray ? helper : CORINFO_HELP_CHKCASTCLASS_SPECIAL;

condTrue = gtNewHelperCallNode(specialHelper, TYP_REF, partialExpand ? op2 : op2Var, gtClone(op1));
}
Expand Down