Skip to content

Commit

Permalink
Fold BOX+ISINST to null if possible (#88989)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored Jul 18, 2023
1 parent 6c3af6a commit 3fafc99
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2911,6 +2911,23 @@ int Compiler::impBoxPatternMatch(CORINFO_RESOLVED_TOKEN* pResolvedToken,
case CEE_ISINST:
if (codeAddr + 1 + sizeof(mdToken) + 1 <= codeEndp)
{
// First, let's see if we can fold BOX+ISINST to just null if ISINST is known to return null
// for the given argument. Don't make inline observations for this case.
if ((opts == BoxPatterns::None) && ((impStackTop().val->gtFlags & GTF_SIDE_EFFECT) == 0) &&
(info.compCompHnd->getBoxHelper(pResolvedToken->hClass) == CORINFO_HELP_BOX))
{
CORINFO_RESOLVED_TOKEN isInstTok;
impResolveToken(codeAddr + 1, &isInstTok, CORINFO_TOKENKIND_Casting);
if (info.compCompHnd->compareTypesForCast(pResolvedToken->hClass, isInstTok.hClass) ==
TypeCompareState::MustNot)
{
JITDUMP("\n Importing BOX; ISINST; as null\n");
impPopStack();
impPushOnStack(gtNewNull(), typeInfo(TYP_REF));
return 1 + sizeof(mdToken);
}
}

const BYTE* nextCodeAddr = codeAddr + 1 + sizeof(mdToken);

switch (nextCodeAddr[0])
Expand Down

0 comments on commit 3fafc99

Please sign in to comment.