Skip to content
Permalink
Browse files

[MERGE #6009 @MikeHolman] disable switch opt when breaking out of loops

Merge pull request #6009 from MikeHolman:switchbug1_11

Cherry-picking to release/1.11 from master.

Switch opt gets confused when we need to branch to labels outside the loop, so just disabling it in this case.
Fixes #5985
  • Loading branch information...
MikeHolman committed Mar 11, 2019
2 parents 42a40b1 + 492ad38 commit d4fb4df5b96d388494adacedfe00487af4918623
Showing with 21 additions and 16 deletions.
  1. +21 −16 lib/Backend/SwitchIRBuilder.cpp
@@ -260,24 +260,29 @@ SwitchIRBuilder::OnCase(IR::RegOpnd * src1Opnd, IR::Opnd * src2Opnd, uint32 offs
//
// For optimizing, the Load instruction corresponding to the switch instruction is profiled in the interpreter.
// Based on the dynamic profile data, optimization technique is decided.
if (m_switchIntDynProfile && isIntConst && GlobOpt::IsSwitchOptEnabledForIntTypeSpec(m_func->GetTopFunc()))
{
CaseNode* caseNode = JitAnew(m_tempAlloc, CaseNode, branchInstr, offset, targetOffset, src2Opnd);
m_caseNodes->Add(caseNode);
}
else if (m_switchStrDynProfile && isStrConst && GlobOpt::IsSwitchOptEnabled(m_func->GetTopFunc()))
{
CaseNode* caseNode = JitAnew(m_tempAlloc, CaseNode, branchInstr, offset, targetOffset, src2Opnd);
m_caseNodes->Add(caseNode);
m_seenOnlySingleCharStrCaseNodes = m_seenOnlySingleCharStrCaseNodes && caseNode->GetUpperBoundStringConstLocal()->GetLength() == 1;
}
else

// TODO: support switch opt when breaking out of loops
if (!m_func->IsLoopBody() || (targetOffset < m_func->m_workItem->GetLoopHeader()->endOffset && targetOffset >= m_func->m_workItem->GetLoopHeader()->startOffset))
{
// Otherwise, there are no optimizations to defer, so add the branch for
// this case instruction now
FlushCases(offset);
m_adapter->AddBranchInstr(branchInstr, offset, targetOffset);
if (m_switchIntDynProfile && isIntConst && GlobOpt::IsSwitchOptEnabledForIntTypeSpec(m_func->GetTopFunc()))
{
CaseNode* caseNode = JitAnew(m_tempAlloc, CaseNode, branchInstr, offset, targetOffset, src2Opnd);
m_caseNodes->Add(caseNode);
return;
}
else if (m_switchStrDynProfile && isStrConst && GlobOpt::IsSwitchOptEnabled(m_func->GetTopFunc()))
{
CaseNode* caseNode = JitAnew(m_tempAlloc, CaseNode, branchInstr, offset, targetOffset, src2Opnd);
m_caseNodes->Add(caseNode);
m_seenOnlySingleCharStrCaseNodes = m_seenOnlySingleCharStrCaseNodes && caseNode->GetUpperBoundStringConstLocal()->GetLength() == 1;
return;
}
}

// Otherwise, there are no optimizations to defer, so add the branch for
// this case instruction now
FlushCases(offset);
m_adapter->AddBranchInstr(branchInstr, offset, targetOffset);
}


0 comments on commit d4fb4df

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.