Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address feedback
  • Loading branch information
EgorBo committed Jan 18, 2024
commit 34523d210fd59e18ca75ec14eaeb8776b7c3b55a
24 changes: 5 additions & 19 deletions src/coreclr/jit/helperexpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,6 @@ bool Compiler::fgLateCastExpansionForCall(BasicBlock** pBlock, Statement* stmt,
lvaSetClass(tmpNum, expectedCls);

// Reload the arguments after the split
clsArg = call->gtArgs.GetUserArgByIndex(0)->GetNode();
GenTree* objArg = call->gtArgs.GetUserArgByIndex(1)->GetNode();
*pBlock = lastBb;

Expand Down Expand Up @@ -1819,22 +1818,14 @@ bool Compiler::fgLateCastExpansionForCall(BasicBlock** pBlock, Statement* stmt,
BasicBlock* nullcheckBb = fgNewBBFromTreeAfter(BBJ_COND, firstBb, gtNewOperNode(GT_JTRUE, TYP_VOID, nullcheckOp),
debugInfo, lastBb, true);

// Insert statements to spill call's arguments (preserving the evaluation order)
// TODO-InlineCast: don't spill cls if possible, we only need it after the nullcheck
const unsigned clsTmp = lvaGrabTemp(true DEBUGARG("local for cls"));
lvaTable[clsTmp].lvType = clsArg->TypeGet();
Statement* storeObjStmt = fgNewStmtAtBeg(nullcheckBb, gtNewTempStore(tmpNum, objArg), debugInfo);
Statement* storeClsStmt = fgNewStmtAtBeg(nullcheckBb, gtNewTempStore(clsTmp, clsArg), debugInfo);
// Set tmp's value to obj by default (before the nullcheck)
Statement* storeObjStmt = fgNewStmtAtBeg(nullcheckBb, gtNewTempStore(tmpNum, gtCloneExpr(objArg)), debugInfo);
gtSetStmtInfo(storeObjStmt);
gtSetStmtInfo(storeClsStmt);
fgSetStmtSeq(storeObjStmt);
fgSetStmtSeq(storeClsStmt);
gtUpdateStmtSideEffects(storeObjStmt);
gtUpdateStmtSideEffects(storeClsStmt);

// if likelyCls == clsArg, we can just use clsArg that we've just spilled to a temp
// it's a sort of manual CSE.
GenTree* likelyClsNode = likelyCls == expectedCls ? gtNewLclVarNode(clsTmp) : gtNewIconEmbClsHndNode(likelyCls);
GenTree* likelyClsNode = gtNewIconEmbClsHndNode(likelyCls);

// Block 2: typeCheckBb
GenTree* mtCheck = gtNewOperNode(GT_EQ, TYP_INT, gtNewMethodTableLookup(gtCloneExpr(objTmp)), likelyClsNode);
Expand All @@ -1843,12 +1834,7 @@ bool Compiler::fgLateCastExpansionForCall(BasicBlock** pBlock, Statement* stmt,
BasicBlock* typeCheckBb = fgNewBBFromTreeAfter(BBJ_COND, nullcheckBb, jtrue, debugInfo, lastBb, true);

// Block 3: fallbackBb
// NOTE: we spilled call's arguments above, we need to re-create it here (we can't just modify call's args)
GenTree* fallbackCall =
gtNewHelperCallNode(call->GetHelperNum(), TYP_REF, gtNewLclVarNode(clsTmp), gtNewLclVarNode(tmpNum));
fallbackCall = fgMorphCall(fallbackCall->AsCall());
gtSetEvalOrder(fallbackCall);
GenTree* fallbackTree = gtNewTempStore(tmpNum, fallbackCall);
GenTree* fallbackTree = gtNewTempStore(tmpNum, call);
BasicBlock* fallbackBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, typeCheckBb, fallbackTree, debugInfo, lastBb, true);

// Block 4: typeCheckSucceedBb
Expand All @@ -1861,7 +1847,7 @@ bool Compiler::fgLateCastExpansionForCall(BasicBlock** pBlock, Statement* stmt,
}
else
{
// Otherwise, no-op (for simplicity, some upstream phase will collect this block)
// Otherwise, no-op (for simplicity, some downstream phase will collect this block)
typeCheckSucceedTree = gtNewNothingNode();
}
BasicBlock* typeCheckSucceedBb =
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5607,7 +5607,6 @@ GenTree* Compiler::impCastClassOrIsInstToTree(
// TODO: enable for cast-class as well.
call->gtCallMoreFlags |= GTF_CALL_M_CAST_CAN_BE_EXPANDED;
call->gtCastHelperILOffset = ilOffset;
setMethodHasExpandableCasts();
}
return call;
}
Expand Down
14 changes: 11 additions & 3 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7697,10 +7697,18 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call)
optMethodFlags |= OMF_NEEDS_GCPOLLS;
}

if (fgGlobalMorph && IsStaticHelperEligibleForExpansion(call))
if (fgGlobalMorph)
{
// Current method has potential candidates for fgExpandStaticInit phase
setMethodHasStaticInit();
if (IsStaticHelperEligibleForExpansion(call))
{
// Current method has potential candidates for fgExpandStaticInit phase
setMethodHasStaticInit();
}
else if ((call->gtCallMoreFlags & GTF_CALL_M_CAST_CAN_BE_EXPANDED) != 0)
{
// Current method has potential candidates for fgLateCastExpansion phase
setMethodHasExpandableCasts();
}
}

// Morph Type.op_Equality, Type.op_Inequality, and Enum.HasFlag
Expand Down