@@ -2424,7 +2424,8 @@ void
24242424GlobOpt::TryReplaceLdLen(IR::Instr *& instr)
24252425{
24262426 // Change LdLen on objects other than arrays, strings, and 'arguments' to LdFld. Otherwise, convert the SymOpnd to a RegOpnd here.
2427- if (instr->m_opcode == Js::OpCode::LdLen_A && instr->GetSrc1() && instr->GetSrc1()->IsSymOpnd())
2427+ // Attempt the same optimisation for GetLength as long as the object is not a typed array
2428+ if ((instr->m_opcode == Js::OpCode::LdLen_A || instr->m_opcode == Js::OpCode::GetLength) && instr->GetSrc1() && instr->GetSrc1()->IsSymOpnd())
24282429 {
24292430 IR::SymOpnd * opnd = instr->GetSrc1()->AsSymOpnd();
24302431 Sym *sym = opnd->m_sym;
@@ -2442,15 +2443,19 @@ GlobOpt::TryReplaceLdLen(IR::Instr *& instr)
24422443 (CurrentBlockData()->argObjSyms && CurrentBlockData()->IsArgumentsOpnd(newopnd))
24432444 )
24442445 {
2445- // We need to properly transfer over the information from the old operand, which is
2446- // a SymOpnd, to the new one, which is a RegOpnd. Unfortunately, the types mean the
2447- // normal copy methods won't work here, so we're going to directly copy data.
2448- newopnd->SetIsJITOptimizedReg(opnd->GetIsJITOptimizedReg());
2449- newopnd->SetValueType(objectValueInfo->Type());
2450- newopnd->SetIsDead(opnd->GetIsDead());
2451- instr->ReplaceSrc1(newopnd);
2446+ // GetLength Op can't be optimised for typed arrays
2447+ if (instr->m_opcode == Js::OpCode::LdLen_A || !objectValueInfo->IsLikelyTypedArray())
2448+ {
2449+ // We need to properly transfer over the information from the old operand, which is
2450+ // a SymOpnd, to the new one, which is a RegOpnd. Unfortunately, the types mean the
2451+ // normal copy methods won't work here, so we're going to directly copy data.
2452+ newopnd->SetIsJITOptimizedReg(opnd->GetIsJITOptimizedReg());
2453+ newopnd->SetValueType(objectValueInfo->Type());
2454+ newopnd->SetIsDead(opnd->GetIsDead());
2455+ instr->ReplaceSrc1(newopnd);
2456+ }
24522457 }
2453- else
2458+ else if(instr->m_opcode == Js::OpCode::LdLen_A) // retain the GetLength op when not optimising
24542459 {
24552460 // otherwise, change the instruction to an LdFld here.
24562461 instr->m_opcode = Js::OpCode::LdFld;
0 commit comments