Skip to content

Commit 1916b15

Browse files
committed
[MERGE #5823 @rajatd] Making Typeof-Br/Cm fast-path more generic
Merge pull request #5823 from rajatd:typeof
2 parents d2f8c41 + 4a0f979 commit 1916b15

File tree

3 files changed

+106
-90
lines changed

3 files changed

+106
-90
lines changed

lib/Backend/Lower.cpp

Lines changed: 99 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -24326,113 +24326,122 @@ Lowerer::TryGenerateFastBrOrCmTypeOf(IR::Instr *instr, IR::Instr **prev, bool is
2432624326

2432724327
if (typeOfDst && instrSrc1 && instrSrc2)
2432824328
{
24329-
IR::RegOpnd *typeOpnd = nullptr;
24330-
IR::RegOpnd *idOpnd = nullptr;
24331-
if (instrSrc1->m_sym == typeOfDst->m_sym)
24329+
do
2433224330
{
24333-
typeOpnd = instrSrc1;
24334-
idOpnd = instrSrc2;
24335-
}
24336-
else if (instrSrc2->m_sym == typeOfDst->m_sym)
24337-
{
24338-
typeOpnd = instrSrc2;
24339-
idOpnd = instrSrc1;
24340-
}
24341-
else
24342-
{
24343-
// Neither source turned out to be the typeOpnd
24344-
return false;
24345-
}
24331+
IR::RegOpnd *typeOpnd = nullptr;
24332+
IR::RegOpnd *idOpnd = nullptr;
24333+
if (instrSrc1->m_sym == typeOfDst->m_sym)
24334+
{
24335+
typeOpnd = instrSrc1;
24336+
idOpnd = instrSrc2;
24337+
}
24338+
else if (instrSrc2->m_sym == typeOfDst->m_sym)
24339+
{
24340+
typeOpnd = instrSrc2;
24341+
idOpnd = instrSrc1;
24342+
}
24343+
else
24344+
{
24345+
// Neither source turned out to be the typeOpnd
24346+
break;
24347+
}
2434624348

24347-
if (!typeOpnd->m_isTempLastUse)
24348-
{
24349-
return false;
24350-
}
24349+
if (!typeOpnd->m_isTempLastUse)
24350+
{
24351+
break;
24352+
}
2435124353

24352-
if (!(idOpnd->m_sym->m_isSingleDef && idOpnd->m_sym->m_isStrConst))
24353-
{
24354-
return false;
24355-
}
24354+
if (!(idOpnd->m_sym->m_isSingleDef && idOpnd->m_sym->m_isStrConst))
24355+
{
24356+
return false;
24357+
}
2435624358

24357-
// The second argument to [Cm|Br]TypeOf is the typeid.
24358-
IR::IntConstOpnd *typeIdOpnd = nullptr;
24359+
// The second argument to [Cm|Br]TypeOf is the typeid.
24360+
IR::IntConstOpnd *typeIdOpnd = nullptr;
2435924361

24360-
Assert(idOpnd->m_sym->m_isSingleDef);
24361-
Assert(idOpnd->m_sym->m_instrDef->GetSrc1()->IsAddrOpnd());
24362+
Assert(idOpnd->m_sym->m_isSingleDef);
24363+
Assert(idOpnd->m_sym->m_instrDef->GetSrc1()->IsAddrOpnd());
2436224364

24363-
// We can't optimize non-javascript type strings.
24364-
JITJavascriptString *typeNameJsString = JITJavascriptString::FromVar(idOpnd->m_sym->m_instrDef->GetSrc1()->AsAddrOpnd()->m_localAddress);
24365-
const char16 *typeName = typeNameJsString->GetString();
24365+
// We can't optimize non-javascript type strings.
24366+
JITJavascriptString *typeNameJsString = JITJavascriptString::FromVar(idOpnd->m_sym->m_instrDef->GetSrc1()->AsAddrOpnd()->m_localAddress);
24367+
const char16 *typeName = typeNameJsString->GetString();
2436624368

24367-
Js::InternalString typeNameString(typeName, typeNameJsString->GetLength());
24368-
if (Js::InternalStringComparer::Equals(typeNameString, Js::Type::UndefinedTypeNameString))
24369-
{
24370-
typeIdOpnd = IR::IntConstOpnd::New(Js::TypeIds_Undefined, TyInt32, instr->m_func);
24371-
}
24372-
else if (Js::InternalStringComparer::Equals(typeNameString, Js::Type::ObjectTypeNameString))
24373-
{
24374-
typeIdOpnd = IR::IntConstOpnd::New(Js::TypeIds_Object, TyInt32, instr->m_func);
24375-
}
24376-
else if (Js::InternalStringComparer::Equals(typeNameString, Js::Type::BooleanTypeNameString))
24377-
{
24378-
typeIdOpnd = IR::IntConstOpnd::New(Js::TypeIds_Boolean, TyInt32, instr->m_func);
24379-
}
24380-
else if (Js::InternalStringComparer::Equals(typeNameString, Js::Type::NumberTypeNameString))
24381-
{
24382-
typeIdOpnd = IR::IntConstOpnd::New(Js::TypeIds_Number, TyInt32, instr->m_func);
24383-
}
24384-
else if (Js::InternalStringComparer::Equals(typeNameString, Js::Type::StringTypeNameString))
24385-
{
24386-
typeIdOpnd = IR::IntConstOpnd::New(Js::TypeIds_String, TyInt32, instr->m_func);
24387-
}
24388-
else if (Js::InternalStringComparer::Equals(typeNameString, Js::Type::FunctionTypeNameString))
24389-
{
24390-
typeIdOpnd = IR::IntConstOpnd::New(Js::TypeIds_Function, TyInt32, instr->m_func);
24391-
}
24392-
else
24393-
{
24394-
return false;
24395-
}
24369+
Js::InternalString typeNameString(typeName, typeNameJsString->GetLength());
24370+
if (Js::InternalStringComparer::Equals(typeNameString, Js::Type::UndefinedTypeNameString))
24371+
{
24372+
typeIdOpnd = IR::IntConstOpnd::New(Js::TypeIds_Undefined, TyInt32, instr->m_func);
24373+
}
24374+
else if (Js::InternalStringComparer::Equals(typeNameString, Js::Type::ObjectTypeNameString))
24375+
{
24376+
typeIdOpnd = IR::IntConstOpnd::New(Js::TypeIds_Object, TyInt32, instr->m_func);
24377+
}
24378+
else if (Js::InternalStringComparer::Equals(typeNameString, Js::Type::BooleanTypeNameString))
24379+
{
24380+
typeIdOpnd = IR::IntConstOpnd::New(Js::TypeIds_Boolean, TyInt32, instr->m_func);
24381+
}
24382+
else if (Js::InternalStringComparer::Equals(typeNameString, Js::Type::NumberTypeNameString))
24383+
{
24384+
typeIdOpnd = IR::IntConstOpnd::New(Js::TypeIds_Number, TyInt32, instr->m_func);
24385+
}
24386+
else if (Js::InternalStringComparer::Equals(typeNameString, Js::Type::StringTypeNameString))
24387+
{
24388+
typeIdOpnd = IR::IntConstOpnd::New(Js::TypeIds_String, TyInt32, instr->m_func);
24389+
}
24390+
else if (Js::InternalStringComparer::Equals(typeNameString, Js::Type::FunctionTypeNameString))
24391+
{
24392+
typeIdOpnd = IR::IntConstOpnd::New(Js::TypeIds_Function, TyInt32, instr->m_func);
24393+
}
24394+
else
24395+
{
24396+
return false;
24397+
}
2439624398

24397-
if (skippedLoads)
24398-
{
24399-
//validate none of dst of Ld_A overlaps with typeof src or dst
24400-
IR::Opnd* typeOfSrc = typeOf->GetSrc1();
24401-
instrLd = typeOf->GetNextRealInstr();
24402-
while (instrLd != instr)
24399+
if (skippedLoads)
2440324400
{
24404-
if (instrLd->GetDst()->IsEqual(typeOfDst) || instrLd->GetDst()->IsEqual(typeOfSrc))
24401+
//validate none of dst of Ld_A overlaps with typeof src or dst
24402+
IR::Opnd* typeOfSrc = typeOf->GetSrc1();
24403+
instrLd = typeOf->GetNextRealInstr();
24404+
while (instrLd != instr)
2440524405
{
24406-
return false;
24406+
if (instrLd->GetDst()->IsEqual(typeOfDst) || instrLd->GetDst()->IsEqual(typeOfSrc))
24407+
{
24408+
return false;
24409+
}
24410+
instrLd = instrLd->GetNextRealInstr();
2440724411
}
24408-
instrLd = instrLd->GetNextRealInstr();
24412+
typeOf->Unlink();
24413+
instr->InsertBefore(typeOf);
24414+
}
24415+
// The first argument to [Cm|Br]TypeOf is the first arg to the TypeOf instruction.
24416+
IR::Opnd *objectOpnd = typeOf->GetSrc1();
24417+
Assert(objectOpnd->IsRegOpnd());
24418+
24419+
// Now emit this instruction and remove the ldstr and typeOf.
24420+
*prev = typeOf->m_prev;
24421+
*pfNoLower = false;
24422+
if (instr->IsBranchInstr())
24423+
{
24424+
GenerateFastBrTypeOf(instr, objectOpnd->AsRegOpnd(), typeIdOpnd, typeOf, pfNoLower, isNeqOp);
24425+
}
24426+
else
24427+
{
24428+
GenerateFastCmTypeOf(instr, objectOpnd->AsRegOpnd(), typeIdOpnd, typeOf, pfNoLower, isNeqOp);
2440924429
}
24410-
typeOf->Unlink();
24411-
instr->InsertBefore(typeOf);
24412-
}
24413-
// The first argument to [Cm|Br]TypeOf is the first arg to the TypeOf instruction.
24414-
IR::Opnd *objectOpnd = typeOf->GetSrc1();
24415-
Assert(objectOpnd->IsRegOpnd());
24416-
24417-
// Now emit this instruction and remove the ldstr and typeOf.
24418-
*prev = typeOf->m_prev;
24419-
*pfNoLower = false;
24420-
if (instr->IsBranchInstr())
24421-
{
24422-
GenerateFastBrTypeOf(instr, objectOpnd->AsRegOpnd(), typeIdOpnd, typeOf, pfNoLower, isNeqOp);
24423-
}
24424-
else
24425-
{
24426-
GenerateFastCmTypeOf(instr, objectOpnd->AsRegOpnd(), typeIdOpnd, typeOf, pfNoLower, isNeqOp);
24427-
}
2442824430

24429-
return true;
24431+
return true;
24432+
} while (false);
2443024433
}
2443124434
}
2443224435

2443324436
if (instrSrc1 && instrSrc1->GetStackSym()->IsSingleDef() && instrSrc2 && instrSrc2->GetStackSym()->IsSingleDef() &&
24434-
instrSrc1->GetStackSym()->GetInstrDef()->m_opcode == Js::OpCode::Typeof &&
24435-
instrSrc2->GetStackSym()->GetInstrDef()->m_opcode == Js::OpCode::Typeof)
24437+
(
24438+
((instrSrc1->GetStackSym()->GetInstrDef()->m_opcode == Js::OpCode::Typeof) &&
24439+
((instrSrc2->GetStackSym()->GetInstrDef()->m_opcode == Js::OpCode::Typeof) || instrSrc2->GetStackSym()->GetIsStrConst()))
24440+
||
24441+
((instrSrc2->GetStackSym()->GetInstrDef()->m_opcode == Js::OpCode::Typeof) &&
24442+
((instrSrc1->GetStackSym()->GetInstrDef()->m_opcode == Js::OpCode::Typeof) || instrSrc1->GetStackSym()->GetIsStrConst()))
24443+
)
24444+
)
2443624445
{
2443724446
*pfNoLower = true;
2443824447
if (instr->IsBranchInstr())

lib/Backend/Sym.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,12 @@ StackSym::SetIsStrConst()
381381
this->m_isNotNumber = true;
382382
}
383383

384+
bool
385+
StackSym::GetIsStrConst()
386+
{
387+
return this->m_isStrConst;
388+
}
389+
384390
Js::RegSlot
385391
StackSym::GetByteCodeRegSlot() const
386392
{

lib/Backend/Sym.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class StackSym: public Sym
128128
void SetIsFloatConst();
129129
void SetIsSimd128Const();
130130
void SetIsStrConst();
131+
bool GetIsStrConst();
131132

132133
intptr_t GetLiteralConstValue_PostGlobOpt() const;
133134
IR::Opnd * GetConstOpnd() const;

0 commit comments

Comments
 (0)