Skip to content

Commit 64376de

Browse files
committed
1 parent 3fe5e24 commit 64376de

File tree

5 files changed

+49
-9
lines changed

5 files changed

+49
-9
lines changed

lib/Backend/BackwardPass.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,6 +2195,13 @@ BackwardPass::DeadStoreTypeCheckBailOut(IR::Instr * instr)
21952195
return;
21962196
}
21972197

2198+
// By default, do not do this for stores, as it makes the presence of type checks unpredictable in the forward pass.
2199+
// For instance, we can't predict which stores may cause reallocation of aux slots.
2200+
if (instr->GetDst() && instr->GetDst()->IsSymOpnd())
2201+
{
2202+
return;
2203+
}
2204+
21982205
IR::BailOutKind oldBailOutKind = instr->GetBailOutKind();
21992206
if (!IR::IsTypeCheckBailOutKind(oldBailOutKind))
22002207
{

lib/Backend/GlobOptFields.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ GlobOpt::FinishOptPropOp(IR::Instr *instr, IR::PropertySymOpnd *opnd, BasicBlock
905905

906906
SymID opndId = opnd->HasObjectTypeSym() ? opnd->GetObjectTypeSym()->m_id : -1;
907907

908-
if (!isObjTypeChecked)
908+
if (!isObjTypeSpecialized || opnd->IsBeingAdded())
909909
{
910910
if (block->globOptData.maybeWrittenTypeSyms == nullptr)
911911
{
@@ -1122,6 +1122,19 @@ GlobOpt::ProcessPropOpInTypeCheckSeq(IR::Instr* instr, IR::PropertySymOpnd *opnd
11221122
Assert(opnd->IsTypeCheckSeqCandidate());
11231123
Assert(opnd->HasObjectTypeSym());
11241124

1125+
if (opnd->HasTypeMismatch())
1126+
{
1127+
if (emitsTypeCheckOut != nullptr)
1128+
{
1129+
*emitsTypeCheckOut = false;
1130+
}
1131+
if (changesTypeValueOut != nullptr)
1132+
{
1133+
*changesTypeValueOut = false;
1134+
}
1135+
return false;
1136+
}
1137+
11251138
bool isStore = opnd == instr->GetDst();
11261139
bool isTypeDead = opnd->IsTypeDead();
11271140
bool consumeType = makeChanges && !IsLoopPrePass();
@@ -1229,7 +1242,7 @@ GlobOpt::ProcessPropOpInTypeCheckSeq(IR::Instr* instr, IR::PropertySymOpnd *opnd
12291242
// a new type value here.
12301243
isSpecialized = false;
12311244

1232-
if (consumeType)
1245+
if (makeChanges)
12331246
{
12341247
opnd->SetTypeMismatch(true);
12351248
}
@@ -1273,7 +1286,7 @@ GlobOpt::ProcessPropOpInTypeCheckSeq(IR::Instr* instr, IR::PropertySymOpnd *opnd
12731286
// a new type value here.
12741287
isSpecialized = false;
12751288

1276-
if (consumeType)
1289+
if (makeChanges)
12771290
{
12781291
opnd->SetTypeMismatch(true);
12791292
}
@@ -1324,7 +1337,7 @@ GlobOpt::ProcessPropOpInTypeCheckSeq(IR::Instr* instr, IR::PropertySymOpnd *opnd
13241337
{
13251338
// Indicates failure/mismatch
13261339
isSpecialized = false;
1327-
if (consumeType)
1340+
if (makeChanges)
13281341
{
13291342
opnd->SetTypeMismatch(true);
13301343
}
@@ -1423,7 +1436,7 @@ GlobOpt::ProcessPropOpInTypeCheckSeq(IR::Instr* instr, IR::PropertySymOpnd *opnd
14231436
// a new type value here.
14241437
isSpecialized = false;
14251438

1426-
if (consumeType)
1439+
if (makeChanges)
14271440
{
14281441
opnd->SetTypeMismatch(true);
14291442
}

lib/Backend/Lower.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7420,9 +7420,6 @@ Lowerer::GenerateStFldWithCachedType(IR::Instr *instrStFld, bool* continueAsHelp
74207420

74217421
if (hasTypeCheckBailout)
74227422
{
7423-
AssertMsg(PHASE_ON1(Js::ObjTypeSpecIsolatedFldOpsWithBailOutPhase) || !propertySymOpnd->IsTypeDead() || propertySymOpnd->TypeCheckRequired(),
7424-
"Why does a field store have a type check bailout, if its type is dead?");
7425-
74267423
if (instrStFld->GetBailOutInfo()->bailOutInstr != instrStFld)
74277424
{
74287425
// Set the cache index in the bailout info so that the generated code will write it into the
@@ -7482,7 +7479,7 @@ Lowerer::GenerateCachedTypeCheck(IR::Instr *instrChk, IR::PropertySymOpnd *prope
74827479
// cache and no type check bailout. In the latter case, we can wind up doing expensive failed equivalence checks
74837480
// repeatedly and never rejit.
74847481
bool doEquivTypeCheck =
7485-
(instrChk->HasEquivalentTypeCheckBailOut() && propertySymOpnd->TypeCheckRequired()) ||
7482+
(instrChk->HasEquivalentTypeCheckBailOut() && (propertySymOpnd->TypeCheckRequired() || propertySymOpnd == instrChk->GetDst())) ||
74867483
(propertySymOpnd->HasEquivalentTypeSet() &&
74877484
!(propertySymOpnd->HasFinalType() && propertySymOpnd->HasInitialType()) &&
74887485
!propertySymOpnd->MustDoMonoCheck() &&

test/fieldopts/OS23440664.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//Reduced Switches: -printsystemexception -maxinterpretcount:1 -maxsimplejitruncount:1 -werexceptionsupport -oopjit- -bvt -off:bailonnoprofile -force:fixdataprops -forcejitloopbody
2+
var shouldBailout = false;
3+
var IntArr0 = [];
4+
function test0() {
5+
var loopInvariant = shouldBailout;
6+
function makeArrayLength() {
7+
return Math.floor();
8+
}
9+
makeArrayLength();
10+
makeArrayLength();
11+
prop0 = 1;
12+
Object;
13+
for (; shouldBailout ? (Object()) : (IntArr0[Object & 1] = '') ? Object : 0;) {
14+
}
15+
}
16+
test0();
17+
WScript.Echo('pass');

test/fieldopts/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,4 +852,10 @@
852852
<files>argobjlengthhoist.js</files>
853853
</default>
854854
</test>
855+
<test>
856+
<default>
857+
<files>OS23440664.js</files>
858+
<compile-flags>-off:bailonnoprofile -force:fixdataprops -forcejitloopbody</compile-flags>
859+
</default>
860+
</test>
855861
</regress-exe>

0 commit comments

Comments
 (0)