Skip to content

Commit

Permalink
JIT: Skip old promotion for retbuf defined locals (#104439)
Browse files Browse the repository at this point in the history
These locals end up being dependently promoted. Skip them and allow
physical promotion to handle them instead.
  • Loading branch information
jakobbotsch authored Jul 5, 2024
1 parent 8a99ada commit 41d854f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/coreclr/jit/fginline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,19 @@ class SubstitutePlaceholdersAndDevirtualizeWalker : public GenTreeVisitor<Substi
#endif // DEBUG
}

// If the inline was rejected and returns a retbuffer, then mark that
// local as DNER now so that promotion knows to leave it up to physical
// promotion.
if ((*use)->IsCall())
{
CallArg* retBuffer = (*use)->AsCall()->gtArgs.GetRetBufferArg();
if ((retBuffer != nullptr) && retBuffer->GetNode()->OperIs(GT_LCL_ADDR))
{
m_compiler->lvaSetVarDoNotEnregister(retBuffer->GetNode()->AsLclVarCommon()->GetLclNum()
DEBUGARG(DoNotEnregisterReason::HiddenBufferStructArg));
}
}

#if FEATURE_MULTIREG_RET
// If an inline was rejected and the call returns a struct, we may
// have deferred some work when importing call for cases where the
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,12 @@ GenTree* Compiler::impStoreStruct(GenTree* store,
GenTree* destAddr = impGetNodeAddr(store, CHECK_SPILL_ALL, &indirFlags);
NewCallArg newArg = NewCallArg::Primitive(destAddr).WellKnown(wellKnownArgType);

if (destAddr->OperIs(GT_LCL_ADDR))
{
lvaSetVarDoNotEnregister(destAddr->AsLclVarCommon()->GetLclNum()
DEBUGARG(DoNotEnregisterReason::HiddenBufferStructArg));
}

#if !defined(TARGET_ARM)
// Unmanaged instance methods on Windows or Unix X86 need the retbuf arg after the first (this) parameter
if ((TargetOS::IsWindows || compUnixX86Abi()) && srcCall->IsUnmanaged())
Expand Down
7 changes: 4 additions & 3 deletions src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2570,9 +2570,11 @@ bool Compiler::StructPromotionHelper::CanPromoteStructVar(unsigned lclNum)
return false;
}

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

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

0 comments on commit 41d854f

Please sign in to comment.