Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize box + isinst + unbox.any as nop #1817

Merged
merged 10 commits into from
Feb 4, 2020
Merged
24 changes: 23 additions & 1 deletion src/coreclr/src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5902,13 +5902,13 @@ int Compiler::impBoxPatternMatch(CORINFO_RESOLVED_TOKEN* pResolvedToken, const B
break;

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])
{
// box + isinst + br_true/false
case CEE_BRTRUE:
case CEE_BRTRUE_S:
case CEE_BRFALSE:
Expand Down Expand Up @@ -5941,6 +5941,28 @@ int Compiler::impBoxPatternMatch(CORINFO_RESOLVED_TOKEN* pResolvedToken, const B
}
}
}
break;

// box + isinst + unbox.any
case CEE_UNBOX_ANY:
if ((nextCodeAddr + 5) <= codeEndp)
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
{
CORINFO_RESOLVED_TOKEN unboxResolvedToken = {};
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
impResolveToken(codeAddr + 1, &unboxResolvedToken, CORINFO_TOKENKIND_Class);
EgorBo marked this conversation as resolved.
Show resolved Hide resolved

// See if the resolved tokens describe types that are equal.
const TypeCompareState compare =
info.compCompHnd->compareTypesForEquality(unboxResolvedToken.hClass,
pResolvedToken->hClass);

// If so, box/unbox.any is a nop.
if (compare == TypeCompareState::Must)
{
JITDUMP("\n Importing BOX; ISINST, UNBOX.ANY as NOP\n");
return 6 + sizeof(mdToken);
}
}
break;
}
}
break;
Expand Down