Skip to content

Commit

Permalink
Move more casts to the late phase
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Feb 11, 2024
1 parent b5411e3 commit 28bc4d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/coreclr/jit/helperexpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1894,9 +1894,9 @@ static int PickCandidatesForTypeCheck(Compiler* comp,
CORINFO_CLASS_HANDLE castToCls = comp->gtGetHelperArgClassHandle(clsArg);
if (castToCls == NO_CLASS_HANDLE)
{
// clsArg doesn't represent a class handle - bail out
// TODO-InlineCast: if CSE becomes a problem - move the whole phase after assertion prop,
// so we can still rely on VN to get the class handle.
// We don't expect the constant handle to be CSE'd here because importer
// sets GTF_DONT_CSE for it. The only case when this arg is not a constant is RUNTIMELOOKUP
// TODO-InlineCast: we should be able to handle RUNTIMELOOKUP as well.
JITDUMP("clsArg is not a constant handle - bail out.\n");
return 0;
}
Expand Down
14 changes: 12 additions & 2 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5514,7 +5514,16 @@ GenTree* Compiler::impCastClassOrIsInstToTree(
}
}

const bool expandInline = canExpandInline && shouldExpandInline;
bool expandInline = canExpandInline && shouldExpandInline;

// Move expansion to the Late Cast Expansion phase.
if (op2->IsIconHandle(GTF_ICON_CLASS_HDL) && (helper != CORINFO_HELP_ISINSTANCEOFCLASS || !isClassExact))
{
// The only two cases left here are:
// 1) isinst <exact class> -- it seems it's profitable to expand such casts early (they don't need helpers)
// 2) late cast expansion doesn't yet support GT_RUNTIMELOOKUP as cast-to yet. (TODO-InlineCast)
expandInline = false;
}

if (!expandInline)
{
Expand All @@ -5529,7 +5538,8 @@ GenTree* Compiler::impCastClassOrIsInstToTree(
GenTreeCall* call = gtNewHelperCallNode(helper, TYP_REF, op2, op1);

// Instrument this castclass/isinst
if ((JitConfig.JitClassProfiling() > 0) && impIsCastHelperEligibleForClassProbe(call) && !isClassExact)
if ((JitConfig.JitClassProfiling() > 0) && impIsCastHelperEligibleForClassProbe(call) && !isClassExact &&
!compCurBB->isRunRarely())
{
// It doesn't make sense to instrument "x is T" or "(T)x" for shared T
if ((info.compCompHnd->getClassAttribs(pResolvedToken->hClass) & CORINFO_FLG_SHAREDINST) == 0)
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/valuenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,8 @@ class ValueNumStore

#ifdef _MSC_VER

assert(&typeid(T) == &typeid(size_t)); // We represent ref/byref constants as size_t's.
assert((&typeid(T) == &typeid(size_t)) ||
(&typeid(T) == &typeid(ssize_t))); // We represent ref/byref constants as size_t/ssize_t

#endif // _MSC_VER

Expand Down

0 comments on commit 28bc4d3

Please sign in to comment.