Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix perf regressions with a recent change. #55300

Merged
merged 3 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 2 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3406,6 +3406,8 @@ class Compiler
void lvaSetVarLiveInOutOfHandler(unsigned varNum);
bool lvaVarDoNotEnregister(unsigned varNum);

void lvSetMinOptsDoNotEnreg();

bool lvaEnregEHVars;
bool lvaEnregMultiRegVars;

Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1585,11 +1585,6 @@ inline unsigned Compiler::lvaGrabTemp(bool shortLifetime DEBUGARG(const char* re
lvaTable[tempNum].lvIsTemp = shortLifetime;
lvaTable[tempNum].lvOnFrame = true;

if (!compEnregLocals())
{
lvaSetVarDoNotEnregister(tempNum DEBUGARG(Compiler::DNER_NoRegVars));
}

// If we've started normal ref counting, bump the ref count of this
// local, as we no longer do any incremental counting, and we presume
// this new local will be referenced.
Expand Down
27 changes: 21 additions & 6 deletions src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1431,11 +1431,6 @@ void Compiler::lvaInitVarDsc(LclVarDsc* varDsc,
}
#endif

if (!compEnregLocals())
{
lvaSetVarDoNotEnregister(varNum DEBUGARG(Compiler::DNER_NoRegVars));
}

#ifdef DEBUG
varDsc->SetStackOffset(BAD_STK_OFFS);
#endif
Expand Down Expand Up @@ -1588,6 +1583,23 @@ bool Compiler::lvaVarDoNotEnregister(unsigned varNum)
return varDsc->lvDoNotEnregister;
}

//------------------------------------------------------------------------
// lvInitializeDoNotEnregFlag: a helper to initialize `lvDoNotEnregister` flag
// for locals that were created before the compiler decided its optimization level.
//
// Assumptions:
// compEnregLocals() value is finalized and is set to false.
//
void Compiler::lvSetMinOptsDoNotEnreg()
{
JITDUMP("compEnregLocals() is false, setting doNotEnreg flag for all locals.");
assert(!compEnregLocals());
for (unsigned lclNum = 0; lclNum < lvaCount; lclNum++)
{
lvaSetVarDoNotEnregister(lclNum DEBUGARG(Compiler::DNER_NoRegVars));
}
}

/*****************************************************************************
* Returns the handle to the class of the local variable varNum
*/
Expand Down Expand Up @@ -2626,7 +2638,6 @@ void Compiler::lvaSetVarDoNotEnregister(unsigned varNum DEBUGARG(DoNotEnregister
break;
case DNER_NoRegVars:
JITDUMP("opts.compFlags & CLFLG_REGVAR is not set\n");
assert((opts.compFlags & CLFLG_REGVAR) == 0);
assert(!compEnregLocals());
break;
case DNER_MinOptsGC:
Expand Down Expand Up @@ -3503,6 +3514,10 @@ void Compiler::lvaSortByRefCount()
varDsc->lvTracked = 0;
lvaSetVarDoNotEnregister(lclNum DEBUGARG(DNER_MinOptsGC));
}
if (!compEnregLocals())
{
lvaSetVarDoNotEnregister(lclNum DEBUGARG(DNER_NoRegVars));
}
#if defined(JIT32_GCENCODER) && defined(FEATURE_EH_FUNCLETS)
if (lvaIsOriginalThisArg(lclNum) && (info.compMethodInfo->options & CORINFO_GENERICS_CTXT_FROM_THIS) != 0)
{
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5886,6 +5886,16 @@ PhaseStatus Lowering::DoPhase()
}
#endif // !defined(TARGET_64BIT)

if (!comp->compEnregLocals())
{
// Lowering is checking if lvDoNotEnregister is already set for contained optimizations.
// If we are running without `CLFLG_REGVAR` flag set (`compEnregLocals() == false`)
// then we already know that we won't enregister any locals and it is better to set
// this flag before we start reading it.
// The main reason why this flag is not set is that we are running in minOpts.
comp->lvSetMinOptsDoNotEnreg();
}

for (BasicBlock* const block : comp->Blocks())
{
/* Make the block publicly available */
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16004,6 +16004,16 @@ void Compiler::fgMorphBlocks()

#endif

if (!compEnregLocals())
{
// Morph is checking if lvDoNotEnregister is already set for some optimizations.
// If we are running without `CLFLG_REGVAR` flag set (`compEnregLocals() == false`)
// then we already know that we won't enregister any locals and it is better to set
// this flag before we start reading it.
// The main reason why this flag is not set is that we are running in minOpts.
lvSetMinOptsDoNotEnreg();
}

/*-------------------------------------------------------------------------
* Process all basic blocks in the function
*/
Expand Down