Restrict to only popping, but not reusing argument slots, as well as only freeing up until the return slots are allocated.

This commit is contained in:
Daniel Kirchner 2021-03-11 17:42:19 +01:00
parent 4b0f8383a6
commit 35c2eeab68

View File

@ -159,7 +159,9 @@ void CodeTransform::freeUnusedVariables(bool _popUnusedSlotsAtStackTop)
deleteVariable(*var);
// Directly in a function body block, we can also delete the function arguments,
// which live in the virtual function scope.
if (!m_scope->functionScope && m_scope->superScope && m_scope->superScope->functionScope)
// However, doing so after the return variables are already allocated, seems to have an adverse
// effect, so we only do it before that.
if (!returnVariablesAndFunctionExitAreSetup() && !m_scope->functionScope && m_scope->superScope && m_scope->superScope->functionScope)
for (auto const& identifier: m_scope->superScope->identifiers)
if (Scope::Variable const* var = get_if<Scope::Variable>(&identifier.second))
if (m_variablesScheduledForDeletion.count(var))
@ -646,6 +648,9 @@ void CodeTransform::setupReturnVariablesAndFunctionExit()
m_scope = m_scope->superScope;
}
// We could reuse unused slots for return variables, but it turns out this is detrimental in practice.
m_unusedStackSlots.clear();
if (m_delayedReturnVariables.empty())
{
m_functionExitStackHeight = 1;