Skip to content

Commit 41d854f

Browse files
authored
JIT: Skip old promotion for retbuf defined locals (#104439)
These locals end up being dependently promoted. Skip them and allow physical promotion to handle them instead.
1 parent 8a99ada commit 41d854f

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/coreclr/jit/fginline.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,19 @@ class SubstitutePlaceholdersAndDevirtualizeWalker : public GenTreeVisitor<Substi
387387
#endif // DEBUG
388388
}
389389

390+
// If the inline was rejected and returns a retbuffer, then mark that
391+
// local as DNER now so that promotion knows to leave it up to physical
392+
// promotion.
393+
if ((*use)->IsCall())
394+
{
395+
CallArg* retBuffer = (*use)->AsCall()->gtArgs.GetRetBufferArg();
396+
if ((retBuffer != nullptr) && retBuffer->GetNode()->OperIs(GT_LCL_ADDR))
397+
{
398+
m_compiler->lvaSetVarDoNotEnregister(retBuffer->GetNode()->AsLclVarCommon()->GetLclNum()
399+
DEBUGARG(DoNotEnregisterReason::HiddenBufferStructArg));
400+
}
401+
}
402+
390403
#if FEATURE_MULTIREG_RET
391404
// If an inline was rejected and the call returns a struct, we may
392405
// have deferred some work when importing call for cases where the

src/coreclr/jit/importer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,12 @@ GenTree* Compiler::impStoreStruct(GenTree* store,
851851
GenTree* destAddr = impGetNodeAddr(store, CHECK_SPILL_ALL, &indirFlags);
852852
NewCallArg newArg = NewCallArg::Primitive(destAddr).WellKnown(wellKnownArgType);
853853

854+
if (destAddr->OperIs(GT_LCL_ADDR))
855+
{
856+
lvaSetVarDoNotEnregister(destAddr->AsLclVarCommon()->GetLclNum()
857+
DEBUGARG(DoNotEnregisterReason::HiddenBufferStructArg));
858+
}
859+
854860
#if !defined(TARGET_ARM)
855861
// Unmanaged instance methods on Windows or Unix X86 need the retbuf arg after the first (this) parameter
856862
if ((TargetOS::IsWindows || compUnixX86Abi()) && srcCall->IsUnmanaged())

src/coreclr/jit/lclvars.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,9 +2570,11 @@ bool Compiler::StructPromotionHelper::CanPromoteStructVar(unsigned lclNum)
25702570
return false;
25712571
}
25722572

2573-
if (varDsc->IsAddressExposed())
2573+
if (varDsc->lvDoNotEnregister)
25742574
{
2575-
JITDUMP(" struct promotion of V%02u is disabled because it has already been marked address exposed\n", lclNum);
2575+
// Promoting structs that are marked DNER will result in dependent
2576+
// promotion. Allow physical promotion to handle these.
2577+
JITDUMP(" struct promotion of V%02u is disabled because it has already been marked DNER\n", lclNum);
25762578
return false;
25772579
}
25782580

@@ -3173,7 +3175,6 @@ void Compiler::lvaSetVarDoNotEnregister(unsigned varNum DEBUGARG(DoNotEnregister
31733175
break;
31743176
case DoNotEnregisterReason::HiddenBufferStructArg:
31753177
JITDUMP("it is hidden buffer struct arg\n");
3176-
assert(varDsc->IsHiddenBufferStructArg());
31773178
break;
31783179
case DoNotEnregisterReason::DontEnregStructs:
31793180
JITDUMP("struct enregistration is disabled\n");

0 commit comments

Comments
 (0)