Skip to content

Commit afdc851

Browse files
committed
PRE fixes - compensation code and avoiding cleanup for PRE instrs' dsts, hoisting LdStr
1 parent 98d556b commit afdc851

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

lib/Backend/FlowGraph.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4227,8 +4227,9 @@ BasicBlock::CleanUpValueMaps()
42274227
{
42284228
FOREACH_SLISTBASE_ENTRY_EDITING(GlobHashBucket, bucket, &thisTable->table[i], iter)
42294229
{
4230-
bool isSymUpwardExposed = upwardExposedUses->Test(bucket.value->m_id) || upwardExposedFields->Test(bucket.value->m_id);
4231-
if (!isSymUpwardExposed && symsInCallSequence.Test(bucket.value->m_id))
4230+
Sym * sym = bucket.value;
4231+
bool isSymUpwardExposed = upwardExposedUses->Test(sym->m_id) || upwardExposedFields->Test(sym->m_id);
4232+
if (!isSymUpwardExposed && symsInCallSequence.Test(sym->m_id))
42324233
{
42334234
// Don't remove/shrink sym-value pair if the sym is referenced in callSequence even if the sym is dead according to backward data flow.
42344235
// This is possible in some edge cases that an infinite loop is involved when evaluating parameter for a function (between StartCall and Call),
@@ -4241,22 +4242,22 @@ BasicBlock::CleanUpValueMaps()
42414242
// Make sure symbol was created before backward pass.
42424243
// If symbols isn't upward exposed, mark it as dead.
42434244
// If a symbol was copy-prop'd in a loop prepass, the upwardExposedUses info could be wrong. So wait until we are out of the loop before clearing it.
4244-
if ((SymID)bucket.value->m_id <= this->globOptData.globOpt->maxInitialSymID && !isSymUpwardExposed
4245-
&& (!isInLoop || !this->globOptData.globOpt->prePassCopyPropSym->Test(bucket.value->m_id)))
4245+
bool isSymFieldPRESymStore = isInLoop && this->loop->fieldPRESymStores->Test(sym->m_id);
4246+
if ((SymID)sym->m_id <= this->globOptData.globOpt->maxInitialSymID && !isSymUpwardExposed && !isSymFieldPRESymStore
4247+
&& (!isInLoop || !this->globOptData.globOpt->prePassCopyPropSym->Test(sym->m_id)))
42464248
{
42474249
Value *val = bucket.element;
42484250
ValueInfo *valueInfo = val->GetValueInfo();
42494251

4250-
Sym * sym = bucket.value;
42514252
Sym *symStore = valueInfo->GetSymStore();
42524253

4253-
if (symStore && symStore == bucket.value)
4254+
if (symStore && symStore == sym)
42544255
{
42554256
// Keep constants around, as we don't know if there will be further uses
42564257
if (!bucket.element->GetValueInfo()->IsVarConstant() && !bucket.element->GetValueInfo()->HasIntConstantValue())
42574258
{
42584259
// Symbol may still be a copy-prop candidate. Wait before deleting it.
4259-
deadSymsBv.Set(bucket.value->m_id);
4260+
deadSymsBv.Set(sym->m_id);
42604261

42614262
// Make sure the type sym is added to the dead syms vector as well, because type syms are
42624263
// created in backward pass and so their symIds > maxInitialSymID.
@@ -4287,8 +4288,6 @@ BasicBlock::CleanUpValueMaps()
42874288
}
42884289
else
42894290
{
4290-
Sym * sym = bucket.value;
4291-
42924291
if (sym->IsPropertySym() && !this->globOptData.liveFields->Test(sym->m_id))
42934292
{
42944293
// Remove propertySyms which are not live anymore.
@@ -4306,7 +4305,7 @@ BasicBlock::CleanUpValueMaps()
43064305

43074306
Sym *symStore = valueInfo->GetSymStore();
43084307

4309-
if (symStore && symStore != bucket.value)
4308+
if (symStore && symStore != sym)
43104309
{
43114310
keepAliveSymsBv.Set(symStore->m_id);
43124311
if (symStore->IsStackSym() && symStore->AsStackSym()->HasObjectTypeSym())

lib/Backend/FlowGraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ class Loop
591591
ValueNumber firstValueNumberInLoop;
592592
JsArrayKills jsArrayKills;
593593
BVSparse<JitArenaAllocator> *fieldKilled;
594-
BVSparse<JitArenaAllocator> *fieldPRESymStore;
594+
BVSparse<JitArenaAllocator> *fieldPRESymStores;
595595
InitialValueFieldMap initialValueFieldMap;
596596

597597
InductionVariableSet *inductionVariables;

lib/Backend/GlobOpt.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ GlobOpt::OptBlock(BasicBlock *block)
450450
if (loop != this->prePassLoop)
451451
{
452452
OptLoops(loop);
453+
if (!IsLoopPrePass() && loop->parent)
454+
{
455+
loop->fieldPRESymStores->Or(loop->parent->fieldPRESymStores);
456+
}
457+
453458
if (!this->IsLoopPrePass() && DoFieldPRE(loop))
454459
{
455460
// Note: !IsLoopPrePass means this was a root loop pre-pass. FieldPre() is called once per loop.
@@ -543,6 +548,7 @@ GlobOpt::OptBlock(BasicBlock *block)
543548
if (succ->isLoopHeader && succ->loop->IsDescendentOrSelf(block->loop))
544549
{
545550
BVSparse<JitArenaAllocator> *liveOnBackEdge = block->loop->regAlloc.liveOnBackEdgeSyms;
551+
liveOnBackEdge->Or(block->loop->fieldPRESymStores);
546552

547553
this->tempBv->Minus(block->loop->varSymsOnEntry, block->globOptData.liveVarSyms);
548554
this->tempBv->And(liveOnBackEdge);
@@ -663,7 +669,7 @@ GlobOpt::OptLoops(Loop *loop)
663669

664670
loop->symsDefInLoop = JitAnew(this->alloc, BVSparse<JitArenaAllocator>, this->alloc);
665671
loop->fieldKilled = JitAnew(alloc, BVSparse<JitArenaAllocator>, this->alloc);
666-
loop->fieldPRESymStore = JitAnew(alloc, BVSparse<JitArenaAllocator>, this->alloc);
672+
loop->fieldPRESymStores = JitAnew(alloc, BVSparse<JitArenaAllocator>, this->alloc);
667673
loop->allFieldsKilled = false;
668674
}
669675
else
@@ -1035,13 +1041,13 @@ BOOL GlobOpt::PreloadPRECandidate(Loop *loop, GlobHashBucket* candidate)
10351041
if (ldInstr->GetDst()->AsRegOpnd()->m_sym != symStore)
10361042
{
10371043
ldInstr->ReplaceDst(IR::RegOpnd::New(symStore->AsStackSym(), TyVar, this->func));
1044+
loop->fieldPRESymStores->Set(symStore->m_id);
10381045
}
10391046

10401047
ldInstr->GetSrc1()->SetIsJITOptimizedReg(true);
10411048
ldInstr->GetDst()->SetIsJITOptimizedReg(true);
10421049

10431050
landingPad->globOptData.liveVarSyms->Set(symStore->m_id);
1044-
loop->fieldPRESymStore->Set(symStore->m_id);
10451051

10461052
ValueType valueType(ValueType::Uninitialized);
10471053
Value *initialValue = nullptr;
@@ -3027,11 +3033,10 @@ GlobOpt::SetLoopFieldInitialValue(Loop *loop, IR::Instr *instr, PropertySym *pro
30273033
Value *initialValue = nullptr;
30283034
StackSym *symStore;
30293035

3030-
if (loop->allFieldsKilled || loop->fieldKilled->Test(originalPropertySym->m_id))
3036+
if (loop->allFieldsKilled || loop->fieldKilled->Test(originalPropertySym->m_id) || loop->fieldKilled->Test(propertySym->m_id))
30313037
{
30323038
return;
30333039
}
3034-
Assert(!loop->fieldKilled->Test(propertySym->m_id));
30353040

30363041
// Value already exists
30373042
if (CurrentBlockData()->FindValue(propertySym))
@@ -14156,7 +14161,6 @@ GlobOpt::OptIsInvariant(
1415614161
return false;
1415714162

1415814163
// Usually not worth hoisting these
14159-
case Js::OpCode::LdStr:
1416014164
case Js::OpCode::Ld_A:
1416114165
case Js::OpCode::Ld_I4:
1416214166
case Js::OpCode::LdC_A_I4:

0 commit comments

Comments
 (0)