Skip to content

Commit d4fb4df

Browse files
committed
[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
2 parents 42a40b1 + 492ad38 commit d4fb4df

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

lib/Backend/SwitchIRBuilder.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -260,24 +260,29 @@ SwitchIRBuilder::OnCase(IR::RegOpnd * src1Opnd, IR::Opnd * src2Opnd, uint32 offs
260260
//
261261
// For optimizing, the Load instruction corresponding to the switch instruction is profiled in the interpreter.
262262
// Based on the dynamic profile data, optimization technique is decided.
263-
if (m_switchIntDynProfile && isIntConst && GlobOpt::IsSwitchOptEnabledForIntTypeSpec(m_func->GetTopFunc()))
264-
{
265-
CaseNode* caseNode = JitAnew(m_tempAlloc, CaseNode, branchInstr, offset, targetOffset, src2Opnd);
266-
m_caseNodes->Add(caseNode);
267-
}
268-
else if (m_switchStrDynProfile && isStrConst && GlobOpt::IsSwitchOptEnabled(m_func->GetTopFunc()))
269-
{
270-
CaseNode* caseNode = JitAnew(m_tempAlloc, CaseNode, branchInstr, offset, targetOffset, src2Opnd);
271-
m_caseNodes->Add(caseNode);
272-
m_seenOnlySingleCharStrCaseNodes = m_seenOnlySingleCharStrCaseNodes && caseNode->GetUpperBoundStringConstLocal()->GetLength() == 1;
273-
}
274-
else
263+
264+
// TODO: support switch opt when breaking out of loops
265+
if (!m_func->IsLoopBody() || (targetOffset < m_func->m_workItem->GetLoopHeader()->endOffset && targetOffset >= m_func->m_workItem->GetLoopHeader()->startOffset))
275266
{
276-
// Otherwise, there are no optimizations to defer, so add the branch for
277-
// this case instruction now
278-
FlushCases(offset);
279-
m_adapter->AddBranchInstr(branchInstr, offset, targetOffset);
267+
if (m_switchIntDynProfile && isIntConst && GlobOpt::IsSwitchOptEnabledForIntTypeSpec(m_func->GetTopFunc()))
268+
{
269+
CaseNode* caseNode = JitAnew(m_tempAlloc, CaseNode, branchInstr, offset, targetOffset, src2Opnd);
270+
m_caseNodes->Add(caseNode);
271+
return;
272+
}
273+
else if (m_switchStrDynProfile && isStrConst && GlobOpt::IsSwitchOptEnabled(m_func->GetTopFunc()))
274+
{
275+
CaseNode* caseNode = JitAnew(m_tempAlloc, CaseNode, branchInstr, offset, targetOffset, src2Opnd);
276+
m_caseNodes->Add(caseNode);
277+
m_seenOnlySingleCharStrCaseNodes = m_seenOnlySingleCharStrCaseNodes && caseNode->GetUpperBoundStringConstLocal()->GetLength() == 1;
278+
return;
279+
}
280280
}
281+
282+
// Otherwise, there are no optimizations to defer, so add the branch for
283+
// this case instruction now
284+
FlushCases(offset);
285+
m_adapter->AddBranchInstr(branchInstr, offset, targetOffset);
281286
}
282287

283288

0 commit comments

Comments
 (0)