Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

JIT: Late expansion for casts#97075

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
EgorBo merged 17 commits intodotnet:mainfromEgorBo:late-cast-expansion
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
de14015
Late expansion of casts
EgorBoJan 17, 2024
2c72dea
Fix build
EgorBoJan 17, 2024
a5345fa
Address feedback
EgorBoJan 17, 2024
efdeae6
Clean up
EgorBoJan 17, 2024
587c66e
Improve TP
EgorBoJan 17, 2024
a72014f
Handle MustNot case
EgorBoJan 17, 2024
b147e67
Final clean up
EgorBoJan 17, 2024
aee96f2
No, this is the final clean up
EgorBoJan 18, 2024
2e6795c
Clean up
EgorBoJan 18, 2024
a5f7079
Apply suggestions from code review
EgorBoJan 18, 2024
34523d2
Address feedback
EgorBoJan 18, 2024
91b47eb
Merge branch 'late-cast-expansion' of github.com:EgorBo/runtime-1 int…
EgorBoJan 18, 2024
c189b80
remove more code
EgorBoJan 18, 2024
6684563
clean up
EgorBoJan 19, 2024
6f42250
Merge branch 'main' of github.com:dotnet/runtime into late-cast-expan…
EgorBoJan 19, 2024
cdb7b47
Fix control flow
EgorBoJan 19, 2024
e1122c8
Clean up
EgorBoJan 19, 2024
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
PrevPrevious commit
NextNext commit
Final clean up
  • Loading branch information
@EgorBo
EgorBo committedJan 17, 2024
commitb147e67c117493660cd1edcda5e1a7e80c38bba1
24 changes: 13 additions & 11 deletionssrc/coreclr/jit/assertionprop.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4764,17 +4764,14 @@ GenTree* Compiler::optAssertionProp_Call(ASSERT_VALARG_TP assertions, GenTreeCal
{
return optAssertionProp_Update(call, call, stmt);
}
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))
else if (!optLocalAssertionProp && call->IsHelperCall())
{
const CorInfoHelpFunc helper = eeGetHelperNum(call->gtCallMethHnd);
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 = call->gtArgs.GetArgByIndex(1)->GetNode();
if (arg1->gtOper != GT_LCL_VAR)
Expand DownExpand Up@@ -4804,6 +4801,11 @@ GenTree* Compiler::optAssertionProp_Call(ASSERT_VALARG_TP assertions, GenTreeCal

return optAssertionProp_Update(arg1, call, stmt);
}

// TODO: check optAssertionIsNonNull for the object argument and replace
// the helper with its nonnull version, e.g.:
// CORINFO_HELP_ISINSTANCEOFANY -> CORINFO_HELP_ISINSTANCEOFANY_NONNULL
// so then fgLateCastExpansion can skip the null check.
}
}

Expand Down
2 changes: 1 addition & 1 deletionsrc/coreclr/jit/compiler.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5056,7 +5056,7 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
DoPhase(this, PHASE_EXPAND_TLS, &Compiler::fgExpandThreadLocalAccess);

// Expand casts
DoPhase(this,PHASE_EXPAND_STATIC_INIT, &Compiler::fgLateCastExpansion);
DoPhase(this,PHASE_EXPAND_CASTS, &Compiler::fgLateCastExpansion);

// Insert GC Polls
DoPhase(this, PHASE_INSERT_GC_POLLS, &Compiler::fgInsertGCPolls);
Expand Down
1 change: 1 addition & 0 deletionssrc/coreclr/jit/compphases.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -98,6 +98,7 @@ CompPhaseNameMacro(PHASE_COMPUTE_EDGE_WEIGHTS2, "Compute edge weights (2, f
CompPhaseNameMacro(PHASE_STRESS_SPLIT_TREE, "Stress gtSplitTree", false, -1, false)
CompPhaseNameMacro(PHASE_EXPAND_RTLOOKUPS, "Expand runtime lookups", false, -1, true)
CompPhaseNameMacro(PHASE_EXPAND_STATIC_INIT, "Expand static init", false, -1, true)
CompPhaseNameMacro(PHASE_EXPAND_CASTS, "Expand casts", false, -1, true)
CompPhaseNameMacro(PHASE_EXPAND_TLS, "Expand TLS access", false, -1, true)
CompPhaseNameMacro(PHASE_INSERT_GC_POLLS, "Insert GC Polls", false, -1, true)
CompPhaseNameMacro(PHASE_CREATE_THROW_HELPERS, "Create throw helper blocks", false, -1, true)
Expand Down
1 change: 1 addition & 0 deletionssrc/coreclr/jit/gentree.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4080,6 +4080,7 @@ enum GenTreeCallFlags : unsigned int
GTF_CALL_M_HAS_LATE_DEVIRT_INFO = 0x01000000, // this call has late devirtualzation info
GTF_CALL_M_LDVIRTFTN_INTERFACE = 0x02000000, // ldvirtftn on an interface type
GTF_CALL_M_CAST_CAN_BE_EXPANDED = 0x04000000, // this cast (helper call) can be expanded if it's profitable
GTF_CALL_M_CAST_NON_NULL = 0x08000000, // this cast (helper call) can be expanded if it's profitable
};

inline constexpr GenTreeCallFlags operator ~(GenTreeCallFlags a)
Expand Down
35 changes: 33 additions & 2 deletionssrc/coreclr/jit/helperexpansion.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1554,6 +1554,25 @@ bool Compiler::fgVNBasedIntrinsicExpansionForCall_ReadUtf8(BasicBlock** pBlock,
return true;
}

//------------------------------------------------------------------------------
// fgLateCastExpansion: Partially inline various cast helpers, e.g.:
//
// tmp = CORINFO_HELP_ISINSTANCEOFINTERFACE(clsHandle, obj);
//
// into:
//
// tmp = obj;
// if ((obj != null) && (obj->pMT != likelyClassHandle))
// {
// tmp = CORINFO_HELP_ISINSTANCEOFINTERFACE(clsHandle, obj);
// }
//
// The goal is to move cast expansion logic from the importer to this phase, for now,
// this phase only supports "isinst" and for profiled casts only.
//
// Returns:
// PhaseStatus indicating what, if anything, was changed.
//
PhaseStatus Compiler::fgLateCastExpansion()
{
if (!doesMethodHaveExpandableCasts())
Expand All@@ -1578,6 +1597,18 @@ PhaseStatus Compiler::fgLateCastExpansion()
return fgExpandHelper<&Compiler::fgLateCastExpansionForCall>(true);
}

//------------------------------------------------------------------------------
// fgLateCastExpansionForCall : Expand specific cast helper, see
// fgLateCastExpansion's comments.
//
// Arguments:
// block - Block containing the cast helper to expand
// stmt - Statement containing the cast helper
// call - The cast helper
//
// Returns:
// True if expanded, false otherwise.
//
bool Compiler::fgLateCastExpansionForCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call)
{
if (!call->IsHelperCall() || !impIsCastHelperMayHaveProfileData(call->GetHelperNum()))
Expand DownExpand Up@@ -1774,15 +1805,15 @@ bool Compiler::fgLateCastExpansionForCall(BasicBlock** pBlock, Statement* stmt,
// Wire up the blocks
//
prevBb->SetTarget(nullcheckBb);
nullcheckBb->SetTrueTarget(fallbackBb);
nullcheckBb->SetTrueTarget(block);
nullcheckBb->SetFalseTarget(typeCheckBb);
typeCheckBb->SetTrueTarget(block);
typeCheckBb->SetFalseTarget(fallbackBb);
fallbackBb->SetTarget(block);
fgRemoveRefPred(block, prevBb);
fgAddRefPred(nullcheckBb, prevBb);
fgAddRefPred(typeCheckBb, nullcheckBb);
fgAddRefPred(fallbackBb, nullcheckBb);
fgAddRefPred(block, nullcheckBb);
fgAddRefPred(fallbackBb, typeCheckBb);
fgAddRefPred(block, typeCheckBb);
fgAddRefPred(block, fallbackBb);
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp