Skip to content

Commit

Permalink
[RyuJIT] Make casthelpers cold for sealed classes (#49295)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored Mar 10, 2021
1 parent beb14c1 commit 016ec29
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2354,12 +2354,12 @@ bool Compiler::fgOptimizeEmptyBlock(BasicBlock* block)
{
case BBJ_COND:
case BBJ_SWITCH:
case BBJ_THROW:

/* can never happen */
noway_assert(!"Conditional, switch, or throw block with empty body!");
noway_assert(!"Conditional or switch block with empty body!");
break;

case BBJ_THROW:
case BBJ_CALLFINALLY:
case BBJ_RETURN:
case BBJ_EHCATCHRET:
Expand Down
10 changes: 6 additions & 4 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11075,9 +11075,6 @@ GenTree* Compiler::impCastClassOrIsInstToTree(GenTree* op1,
condTrue = gtNewIconNode(0, TYP_REF);
}

#define USE_QMARK_TREES

#ifdef USE_QMARK_TREES
GenTree* qmarkMT;
//
// Generate first QMARK - COLON tree
Expand All @@ -11091,6 +11088,12 @@ GenTree* Compiler::impCastClassOrIsInstToTree(GenTree* op1,
temp = new (this, GT_COLON) GenTreeColon(TYP_REF, condTrue, condFalse);
qmarkMT = gtNewQmarkNode(TYP_REF, condMT, temp);

if (isCastClass && impIsClassExact(pResolvedToken->hClass) && condTrue->OperIs(GT_CALL))
{
// condTrue is used only for throwing InvalidCastException in case of casting to an exact class.
condTrue->AsCall()->gtCallMoreFlags |= GTF_CALL_M_DOES_NOT_RETURN;
}

GenTree* qmarkNull;
//
// Generate second QMARK - COLON tree
Expand Down Expand Up @@ -11119,7 +11122,6 @@ GenTree* Compiler::impCastClassOrIsInstToTree(GenTree* op1,
JITDUMP("Marked V%02u as a single def temp\n", tmp);
lvaSetClass(tmp, pResolvedToken->hClass);
return gtNewLclvNode(tmp, TYP_REF);
#endif
}

#ifndef DEBUG
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17689,6 +17689,11 @@ void Compiler::fgExpandQmarkForCastInstOf(BasicBlock* block, Statement* stmt)
// Finally remove the nested qmark stmt.
fgRemoveStmt(block, stmt);

if (true2Expr->OperIs(GT_CALL) && (true2Expr->AsCall()->gtCallMoreFlags & GTF_CALL_M_DOES_NOT_RETURN))
{
fgConvertBBToThrowBB(helperBlock);
}

#ifdef DEBUG
if (verbose)
{
Expand Down

0 comments on commit 016ec29

Please sign in to comment.