Skip to content

Commit 70aa49a

Browse files
committed
[MERGE #5618 @rajatd] Copy-prop ScopedLdFld. OS#18622681
Merge pull request #5618 from rajatd:scopedLdFld-2 Enable copy-prop of ScopedLdFld and ScopedLdFldForTypeOf.
2 parents 97eeb2f + cff87d0 commit 70aa49a

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

lib/Backend/GlobOpt.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3289,6 +3289,7 @@ GlobOpt::OptSrc(IR::Opnd *opnd, IR::Instr * *pInstr, Value **indirIndexValRef, I
32893289
case Js::OpCode::BrOnHasProperty:
32903290
case Js::OpCode::LdMethodFldPolyInlineMiss:
32913291
case Js::OpCode::StSlotChkUndecl:
3292+
case Js::OpCode::ScopedLdInst:
32923293
return nullptr;
32933294
};
32943295

@@ -3718,6 +3719,8 @@ GlobOpt::CopyProp(IR::Opnd *opnd, IR::Instr *instr, Value *val, IR::IndirOpnd *p
37183719
case Js::OpCode::LdRootMethodFld:
37193720
case Js::OpCode::LdMethodFromFlags:
37203721
case Js::OpCode::ScopedLdMethodFld:
3722+
case Js::OpCode::ScopedLdFld:
3723+
case Js::OpCode::ScopedLdFldForTypeOf:
37213724
instr->m_opcode = Js::OpCode::Ld_A;
37223725
case Js::OpCode::Ld_A:
37233726
{
@@ -3956,6 +3959,8 @@ GlobOpt::CopyPropReplaceOpnd(IR::Instr * instr, IR::Opnd * opnd, StackSym * copy
39563959
case Js::OpCode::LdMethodFld:
39573960
case Js::OpCode::LdRootMethodFld:
39583961
case Js::OpCode::ScopedLdMethodFld:
3962+
case Js::OpCode::ScopedLdFld:
3963+
case Js::OpCode::ScopedLdFldForTypeOf:
39593964
instr->m_opcode = Js::OpCode::Ld_A;
39603965
break;
39613966

@@ -4682,13 +4687,16 @@ GlobOpt::ValueNumberDst(IR::Instr **pInstr, Value *src1Val, Value *src2Val)
46824687
case Js::OpCode::LdFld:
46834688
case Js::OpCode::LdFldForTypeOf:
46844689
case Js::OpCode::LdFldForCallApplyTarget:
4685-
// Do not transfer value type on ldFldForTypeOf to prevent copy-prop to LdRootFld in case the field doesn't exist since LdRootFldForTypeOf does not throw
4690+
// Do not transfer value type on LdRootFldForTypeOf to prevent copy-prop to LdRootFld in case the field doesn't exist since LdRootFldForTypeOf does not throw.
4691+
// Same goes for ScopedLdFldForTypeOf as we'll end up loading the property from the root object if the property is not in the scope chain.
46864692
//case Js::OpCode::LdRootFldForTypeOf:
4693+
//case Js::OpCode::ScopedLdFldForTypeOf:
46874694
case Js::OpCode::LdRootFld:
46884695
case Js::OpCode::LdMethodFld:
46894696
case Js::OpCode::LdRootMethodFld:
46904697
case Js::OpCode::ScopedLdMethodFld:
46914698
case Js::OpCode::LdMethodFromFlags:
4699+
case Js::OpCode::ScopedLdFld:
46924700
if (instr->IsProfiledInstr())
46934701
{
46944702
ValueType profiledValueType(instr->AsProfiledInstr()->u.FldInfo().valueType);

lib/Backend/GlobOptFields.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,6 @@ GlobOpt::AssertCanCopyPropOrCSEFieldLoad(IR::Instr * instr)
566566
// Consider: Hoisting LdRootFld may have complication with exception if the field doesn't exist.
567567
// We need to have another opcode for the hoisted version to avoid the exception and bailout.
568568

569-
// Consider: Theoretically, we can copy prop/field hoist ScopedLdFld/ScopedStFld
570-
// but Instr::TransferSrcValue blocks that now, and copy prop into that instruction is not supported yet.
571569
Assert(instr->m_opcode == Js::OpCode::LdSlot || instr->m_opcode == Js::OpCode::LdSlotArr
572570
|| instr->m_opcode == Js::OpCode::LdFld || instr->m_opcode == Js::OpCode::LdFldForCallApplyTarget
573571
|| instr->m_opcode == Js::OpCode::LdLen_A
@@ -578,7 +576,9 @@ GlobOpt::AssertCanCopyPropOrCSEFieldLoad(IR::Instr * instr)
578576
|| instr->m_opcode == Js::OpCode::LdMethodFromFlags
579577
|| instr->m_opcode == Js::OpCode::ScopedLdMethodFld
580578
|| instr->m_opcode == Js::OpCode::CheckFixedFld
581-
|| instr->m_opcode == Js::OpCode::CheckPropertyGuardAndLoadType);
579+
|| instr->m_opcode == Js::OpCode::CheckPropertyGuardAndLoadType
580+
|| instr->m_opcode == Js::OpCode::ScopedLdFld
581+
|| instr->m_opcode == Js::OpCode::ScopedLdFldForTypeOf);
582582

583583
Assert(instr->m_opcode == Js::OpCode::CheckFixedFld || instr->GetDst()->GetType() == TyVar || instr->m_func->GetJITFunctionBody()->IsAsmJsMode());
584584
Assert(instr->GetSrc1()->GetType() == TyVar || instr->m_func->GetJITFunctionBody()->IsAsmJsMode());

lib/Backend/IR.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3305,7 +3305,6 @@ bool Instr::TransfersSrcValue()
33053305
// No point creating an unknown value for the src of a binary instr, as the dst will just be a different
33063306
// Don't create value for instruction without dst as well. The value doesn't go anywhere.
33073307

3308-
// if (src2 == nullptr) Disable copy prop for ScopedLdFld/ScopeStFld, etc., consider enabling that in the future
33093308
// Consider: Add opcode attribute to indicate whether the opcode would use the value or not
33103309

33113310
return this->GetDst() != nullptr && this->GetSrc2() == nullptr && !OpCodeAttr::DoNotTransfer(this->m_opcode) && !this->CallsAccessor();

lib/Backend/IRBuilder.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,10 +3124,9 @@ IRBuilder::BuildElementScopedC(Js::OpCode newOpcode, uint32 offset, Js::RegSlot
31243124
case Js::OpCode::ScopedDeleteFld:
31253125
case Js::OpCode::ScopedDeleteFldStrict:
31263126
{
3127-
// Implicit root object as default instance
3128-
IR::Opnd * instance2Opnd = this->BuildSrcOpnd(Js::FunctionBody::RootObjectRegSlot);
3127+
Assert(this->m_func->GetScriptContextInfo()->GetAddr() == this->m_func->GetTopFunc()->GetScriptContextInfo()->GetAddr());
31293128
regOpnd = this->BuildDstOpnd(regSlot);
3130-
instr = IR::Instr::New(newOpcode, regOpnd, fieldSymOpnd, instance2Opnd, m_func);
3129+
instr = IR::Instr::New(newOpcode, regOpnd, fieldSymOpnd, m_func);
31313130
break;
31323131
}
31333132

@@ -4363,13 +4362,12 @@ IRBuilder::BuildElementP(Js::OpCode newOpcode, uint32 offset, Js::RegSlot regSlo
43634362
case Js::OpCode::ScopedLdFldForTypeOf:
43644363
{
43654364
Assert(!isProfiled);
4365+
Assert(this->m_func->GetScriptContextInfo()->GetAddr() == this->m_func->GetTopFunc()->GetScriptContextInfo()->GetAddr());
43664366

43674367
fieldSymOpnd = this->BuildFieldOpnd(newOpcode, instance, propertyId, (Js::PropertyIdIndexType)-1, PropertyKindData, inlineCacheIndex);
43684368

4369-
// Implicit root object as default instance
4370-
IR::Opnd * instance2Opnd = this->BuildSrcOpnd(Js::FunctionBody::RootObjectRegSlot);
43714369
regOpnd = this->BuildDstOpnd(regSlot);
4372-
instr = IR::Instr::New(newOpcode, regOpnd, fieldSymOpnd, instance2Opnd, m_func);
4370+
instr = IR::Instr::New(newOpcode, regOpnd, fieldSymOpnd, m_func);
43734371
break;
43744372
}
43754373

lib/Backend/Lower.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6888,8 +6888,8 @@ Lowerer::LowerScopedLdFld(IR::Instr * ldFldInstr, IR::JnHelperMethod helperMetho
68886888
LoadScriptContext(ldFldInstr);
68896889
}
68906890

6891-
src = ldFldInstr->UnlinkSrc2();
6892-
AssertMsg(src->IsRegOpnd(), "Expected reg opnd as src2");
6891+
intptr_t rootObject = m_func->GetJITFunctionBody()->GetRootObject();
6892+
src = IR::AddrOpnd::New(rootObject, IR::AddrOpndKindDynamicVar, this->m_func, true);
68936893
instrPrev = m_lowererMD.LoadHelperArgument(ldFldInstr, src);
68946894

68956895
src = ldFldInstr->UnlinkSrc1();

lib/Backend/LowerMDShared.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4101,11 +4101,6 @@ LowererMD::GenerateFastScopedLdFld(IR::Instr * instrLdScopedFld)
41014101

41024102
opndBase = propertySymOpnd->CreatePropertyOwnerOpnd(m_func);
41034103

4104-
IR::Opnd *srcBase = instrLdScopedFld->GetSrc2();
4105-
AssertMsg(srcBase->IsRegOpnd(), "Expected reg opnd as src2");
4106-
//opndBase = srcBase;
4107-
4108-
//IR::IndirOpnd * indirOpnd = src->AsIndirOpnd();
41094104
labelHelper = IR::LabelInstr::New(Js::OpCode::Label, this->m_func, true);
41104105

41114106
AssertMsg(opndBase->m_sym->m_isSingleDef, "We assume this isn't redefined");

0 commit comments

Comments
 (0)