Skip to content

Commit

Permalink
convert to BBJ_THROW
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Mar 9, 2021
1 parent cb620ff commit 23989d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
25 changes: 16 additions & 9 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3959,15 +3959,22 @@ GenTree* Compiler::optAssertionProp_Call(ASSERT_VALARG_TP assertions, GenTreeCal
}
else if (!optLocalAssertionProp && (call->gtCallType == CT_HELPER))
{
if (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_ISINSTANCEOFINTERFACE) ||
call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_ISINSTANCEOFARRAY) ||
call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_ISINSTANCEOFCLASS) ||
call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_ISINSTANCEOFANY) ||
call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_CHKCASTINTERFACE) ||
call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_CHKCASTARRAY) ||
call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_CHKCASTCLASS) ||
call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_CHKCASTANY) ||
call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_CHKCASTCLASS_SPECIAL))
CorInfoHelpFunc helper = eeGetHelperNum(call->gtCallMethHnd);

if ((helper == CORINFO_HELP_CHKCASTCLASS_SPECIAL) && (call->gtCallMoreFlags & GTF_CALL_M_DOES_NOT_RETURN))
{
return nullptr;
}

if ((helper == CORINFO_HELP_ISINSTANCEOFINTERFACE) ||
(helper == CORINFO_HELP_ISINSTANCEOFARRAY) ||
(helper == CORINFO_HELP_ISINSTANCEOFCLASS) ||
(helper == CORINFO_HELP_ISINSTANCEOFANY) ||
(helper == CORINFO_HELP_CHKCASTINTERFACE) ||
(helper == CORINFO_HELP_CHKCASTARRAY) ||
(helper == CORINFO_HELP_CHKCASTCLASS) ||
(helper == CORINFO_HELP_CHKCASTANY) ||
(helper == CORINFO_HELP_CHKCASTCLASS_SPECIAL))
{
GenTree* arg1 = gtArgEntryByArgNum(call, 1)->GetNode();
if (arg1->gtOper != GT_LCL_VAR)
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 @@ -17698,6 +17698,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 23989d0

Please sign in to comment.