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

Commit26d8316

Browse files
JIT: Late expansion for profiled isinst (#97075)
Co-authored-by: Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>
1 parent843316f commit26d8316

File tree

8 files changed

+411
-17
lines changed

8 files changed

+411
-17
lines changed

‎src/coreclr/jit/assertionprop.cpp‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4764,17 +4764,14 @@ GenTree* Compiler::optAssertionProp_Call(ASSERT_VALARG_TP assertions, GenTreeCal
47644764
{
47654765
returnoptAssertionProp_Update(call, call, stmt);
47664766
}
4767-
elseif (!optLocalAssertionProp && (call->gtCallType == CT_HELPER))
4768-
{
4769-
if (call->gtCallMethHnd ==eeFindHelper(CORINFO_HELP_ISINSTANCEOFINTERFACE) ||
4770-
call->gtCallMethHnd ==eeFindHelper(CORINFO_HELP_ISINSTANCEOFARRAY) ||
4771-
call->gtCallMethHnd ==eeFindHelper(CORINFO_HELP_ISINSTANCEOFCLASS) ||
4772-
call->gtCallMethHnd ==eeFindHelper(CORINFO_HELP_ISINSTANCEOFANY) ||
4773-
call->gtCallMethHnd ==eeFindHelper(CORINFO_HELP_CHKCASTINTERFACE) ||
4774-
call->gtCallMethHnd ==eeFindHelper(CORINFO_HELP_CHKCASTARRAY) ||
4775-
call->gtCallMethHnd ==eeFindHelper(CORINFO_HELP_CHKCASTCLASS) ||
4776-
call->gtCallMethHnd ==eeFindHelper(CORINFO_HELP_CHKCASTANY) ||
4777-
call->gtCallMethHnd ==eeFindHelper(CORINFO_HELP_CHKCASTCLASS_SPECIAL))
4767+
elseif (!optLocalAssertionProp && call->IsHelperCall())
4768+
{
4769+
const CorInfoHelpFunc helper =eeGetHelperNum(call->gtCallMethHnd);
4770+
if ((helper == CORINFO_HELP_ISINSTANCEOFINTERFACE) || (helper == CORINFO_HELP_ISINSTANCEOFARRAY) ||
4771+
(helper == CORINFO_HELP_ISINSTANCEOFCLASS) || (helper == CORINFO_HELP_ISINSTANCEOFANY) ||
4772+
(helper == CORINFO_HELP_CHKCASTINTERFACE) || (helper == CORINFO_HELP_CHKCASTARRAY) ||
4773+
(helper == CORINFO_HELP_CHKCASTCLASS) || (helper == CORINFO_HELP_CHKCASTANY) ||
4774+
(helper == CORINFO_HELP_CHKCASTCLASS_SPECIAL))
47784775
{
47794776
GenTree* arg1 = call->gtArgs.GetArgByIndex(1)->GetNode();
47804777
if (arg1->gtOper != GT_LCL_VAR)
@@ -4804,6 +4801,11 @@ GenTree* Compiler::optAssertionProp_Call(ASSERT_VALARG_TP assertions, GenTreeCal
48044801

48054802
returnoptAssertionProp_Update(arg1, call, stmt);
48064803
}
4804+
4805+
// TODO-InlineCast: check optAssertionIsNonNull for the object argument and replace
4806+
// the helper with its nonnull version, e.g.:
4807+
// CORINFO_HELP_ISINSTANCEOFANY -> CORINFO_HELP_ISINSTANCEOFANY_NONNULL
4808+
// so then fgLateCastExpansion can skip the null check.
48074809
}
48084810
}
48094811

‎src/coreclr/jit/compiler.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5046,6 +5046,9 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
50465046
// Expand thread local access
50475047
DoPhase(this, PHASE_EXPAND_TLS, &Compiler::fgExpandThreadLocalAccess);
50485048

5049+
// Expand casts
5050+
DoPhase(this, PHASE_EXPAND_CASTS, &Compiler::fgLateCastExpansion);
5051+
50495052
// Insert GC Polls
50505053
DoPhase(this, PHASE_INSERT_GC_POLLS, &Compiler::fgInsertGCPolls);
50515054

‎src/coreclr/jit/compiler.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5832,6 +5832,9 @@ class Compiler
58325832
boolfgVNBasedIntrinsicExpansionForCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call);
58335833
boolfgVNBasedIntrinsicExpansionForCall_ReadUtf8(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call);
58345834

5835+
PhaseStatusfgLateCastExpansion();
5836+
boolfgLateCastExpansionForCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call);
5837+
58355838
PhaseStatusfgInsertGCPolls();
58365839
BasicBlock*fgCreateGCPoll(GCPollType pollType, BasicBlock* block);
58375840

@@ -7523,6 +7526,7 @@ class Compiler
75237526
#defineOMF_HAS_TLS_FIELD0x00010000// Method contains TLS field access
75247527
#defineOMF_HAS_SPECIAL_INTRINSICS0x00020000// Method contains special intrinsics expanded in late phases
75257528
#defineOMF_HAS_RECURSIVE_TAILCALL0x00040000// Method contains recursive tail call
7529+
#defineOMF_HAS_EXPANDABLE_CAST0x00080000// Method contains casts eligible for late expansion
75267530

75277531
// clang-format on
75287532

@@ -7563,6 +7567,16 @@ class Compiler
75637567
optMethodFlags |= OMF_HAS_STATIC_INIT;
75647568
}
75657569

7570+
booldoesMethodHaveExpandableCasts()
7571+
{
7572+
return (optMethodFlags & OMF_HAS_EXPANDABLE_CAST) !=0;
7573+
}
7574+
7575+
voidsetMethodHasExpandableCasts()
7576+
{
7577+
optMethodFlags |= OMF_HAS_EXPANDABLE_CAST;
7578+
}
7579+
75667580
booldoesMethodHaveGuardedDevirtualization()const
75677581
{
75687582
return (optMethodFlags & OMF_HAS_GUARDEDDEVIRT) !=0;

‎src/coreclr/jit/compphases.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ CompPhaseNameMacro(PHASE_COMPUTE_EDGE_WEIGHTS2, "Compute edge weights (2, f
9898
CompPhaseNameMacro(PHASE_STRESS_SPLIT_TREE,"Stress gtSplitTree", false,-1, false)
9999
CompPhaseNameMacro(PHASE_EXPAND_RTLOOKUPS,"Expand runtime lookups", false,-1, true)
100100
CompPhaseNameMacro(PHASE_EXPAND_STATIC_INIT,"Expand static init", false,-1, true)
101+
CompPhaseNameMacro(PHASE_EXPAND_CASTS,"Expand casts", false,-1, true)
101102
CompPhaseNameMacro(PHASE_EXPAND_TLS,"Expand TLS access", false,-1, true)
102103
CompPhaseNameMacro(PHASE_INSERT_GC_POLLS,"Insert GC Polls", false,-1, true)
103104
CompPhaseNameMacro(PHASE_CREATE_THROW_HELPERS,"Create throw helper blocks", false,-1, true)

‎src/coreclr/jit/gentree.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4123,6 +4123,7 @@ enum GenTreeCallFlags : unsigned int
41234123
GTF_CALL_M_EXPANDED_EARLY =0x00800000,// the Virtual Call target address is expanded and placed in gtControlExpr in Morph rather than in Lower
41244124
GTF_CALL_M_HAS_LATE_DEVIRT_INFO =0x01000000,// this call has late devirtualzation info
41254125
GTF_CALL_M_LDVIRTFTN_INTERFACE =0x02000000,// ldvirtftn on an interface type
4126+
GTF_CALL_M_CAST_CAN_BE_EXPANDED =0x04000000,// this cast (helper call) can be expanded if it's profitable. To be removed.
41264127
};
41274128

41284129
inlineconstexpr GenTreeCallFlagsoperator ~(GenTreeCallFlags a)
@@ -5631,8 +5632,9 @@ struct GenTreeCall final : public GenTree
56315632

56325633
CORINFO_CLASS_HANDLE gtRetClsHnd;// The return type handle of the call if it is a struct; always available
56335634
union {
5634-
void* gtStubCallStubAddr;// GTF_CALL_VIRT_STUB - these are never inlined
5635-
CORINFO_CLASS_HANDLE gtInitClsHnd;// Used by static init helpers, represents a class they init
5635+
void* gtStubCallStubAddr;// GTF_CALL_VIRT_STUB - these are never inlined
5636+
CORINFO_CLASS_HANDLE gtInitClsHnd;// Used by static init helpers, represents a class they init
5637+
IL_OFFSET gtCastHelperILOffset;// Used by cast helpers to save corresponding IL offset
56365638
};
56375639

56385640
union {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp