Skip to content

Commit

Permalink
[MERGE #6009 @MikeHolman] disable switch opt when breaking out of loops
Browse files Browse the repository at this point in the history
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 d4fb4df
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions lib/Backend/SwitchIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down

0 comments on commit d4fb4df

Please sign in to comment.