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 doNotEnreg regressions. #55257

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4069,6 +4069,8 @@ void Compiler::compSetOptimizationLevel()
#endif

fgCanRelocateEHRegions = true;

lvInitializeDoNotEnregFlag();
}

#ifdef TARGET_ARMARCH
Expand Down
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 lvInitializeDoNotEnregFlag();

bool lvaEnregEHVars;
bool lvaEnregMultiRegVars;

Expand Down
32 changes: 28 additions & 4 deletions src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,26 @@ 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:
// There were no temp vars created so far, only actual IL locals, arguments etc.
//
void Compiler::lvInitializeDoNotEnregFlag()
{
JITDUMP("Switching locals to another optimization level, resetting lvDoNotEnregister flag.\n")
for (unsigned lclNum = 0; lclNum < lvaCount; lclNum++)
{
assert(!lvaVarDoNotEnregister(lclNum));
if (!compEnregLocals())
{
lvaSetVarDoNotEnregister(lclNum DEBUGARG(Compiler::DNER_NoRegVars));
}
}
}

/*****************************************************************************
* Returns the handle to the class of the local variable varNum
*/
Expand Down Expand Up @@ -2582,10 +2602,7 @@ void Compiler::lvaSetVarDoNotEnregister(unsigned varNum DEBUGARG(DoNotEnregister
varDsc->lvDoNotEnregister = 1;

#ifdef DEBUG
if (verbose)
{
printf("\nLocal V%02u should not be enregistered because: ", varNum);
}
JITDUMP("\nLocal V%02u should not be enregistered because: ", varNum);
switch (reason)
{
case DNER_AddrExposed:
Expand Down Expand Up @@ -3512,6 +3529,13 @@ void Compiler::lvaSortByRefCount()
}
#endif

#if defined(DEBUG)
if (!compEnregLocals())
{
assert(varDsc->lvDoNotEnregister);
}
#endif // DEBUG

// Are we not optimizing and we have exception handlers?
// if so mark all args and locals "do not enregister".
//
Expand Down