@@ -235,15 +235,16 @@ SwitchIRBuilder::OnCase(IR::RegOpnd * src1Opnd, IR::Opnd * src2Opnd, uint32 offs
235235    const  bool  isIntConst = src2Opnd->IsIntConstOpnd () || (sym && sym->IsIntConst ());
236236    const  bool  isStrConst = !isIntConst && sym && sym->m_isStrConst ;
237237
238-     if  (GlobOpt::IsSwitchOptEnabled (m_func-> GetTopFunc ()) &&  
239-         isIntConst  && 
240-         m_intConstSwitchCases->TestAndSet (sym ? sym->GetIntConstValue () : src2Opnd->AsIntConstOpnd ()->AsInt32 ()))
238+     if  (isIntConst 
239+         && GlobOpt::IsSwitchOptEnabledForIntTypeSpec (m_func-> GetTopFunc ()) 
240+         &&  m_intConstSwitchCases->TestAndSet (sym ? sym->GetIntConstValue () : src2Opnd->AsIntConstOpnd ()->AsInt32 ()))
241241    {
242242        //  We've already seen a case statement with the same int const value. No need to emit anything for this.
243243        return ;
244244    }
245245
246-     if  (GlobOpt::IsSwitchOptEnabled (m_func->GetTopFunc ()) && isStrConst
246+     if  (isStrConst
247+         && GlobOpt::IsSwitchOptEnabled (m_func->GetTopFunc ())
247248        && TestAndAddStringCaseConst (JITJavascriptString::FromVar (sym->GetConstAddress (true ))))
248249    {
249250        //  We've already seen a case statement with the same string const value. No need to emit anything for this.
@@ -253,36 +254,27 @@ SwitchIRBuilder::OnCase(IR::RegOpnd * src1Opnd, IR::Opnd * src2Opnd, uint32 offs
253254    branchInstr = IR::BranchInstr::New (m_eqOp, nullptr , src1Opnd, src2Opnd, m_func);
254255    branchInstr->m_isSwitchBr  = true ;
255256
256-     /* 
257257    //   Switch optimization
258258    //   For Integers - Binary Search or jump table optimization technique is used
259259    //   For Strings - Dictionary look up technique is used.
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-     */  
264- 
265-     bool  deferred = false ;
266- 
267-     if  (GlobOpt::IsSwitchOptEnabled (m_func->GetTopFunc ()))
263+     if  (m_switchIntDynProfile && isIntConst && GlobOpt::IsSwitchOptEnabledForIntTypeSpec (m_func->GetTopFunc ()))
268264    {
269-         if  (m_switchIntDynProfile && isIntConst)
270-         {
271-             CaseNode* caseNode = JitAnew (m_tempAlloc, CaseNode, branchInstr, offset, targetOffset, src2Opnd);
272-             m_caseNodes->Add (caseNode);
273-             deferred = true ;
274-         }
275-         else  if  (m_switchStrDynProfile && isStrConst)
276-         {
277-             CaseNode* caseNode = JitAnew (m_tempAlloc, CaseNode, branchInstr, offset, targetOffset, src2Opnd);
278-             m_caseNodes->Add (caseNode);
279-             m_seenOnlySingleCharStrCaseNodes = m_seenOnlySingleCharStrCaseNodes && caseNode->GetUpperBoundStringConstLocal ()->GetLength () == 1 ;
280-             deferred = true ;
281-         }
265+         CaseNode* caseNode = JitAnew (m_tempAlloc, CaseNode, branchInstr, offset, targetOffset, src2Opnd);
266+         m_caseNodes->Add (caseNode);
282267    }
283- 
284-     if  (!deferred)
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 
285275    {
276+         //  Otherwise, there are no optimizations to defer, so add the branch for
277+         //  this case instruction now
286278        FlushCases (offset);
287279        m_adapter->AddBranchInstr (branchInstr, offset, targetOffset);
288280    }
0 commit comments