@@ -14402,7 +14402,8 @@ GlobOpt::OptArraySrc(IR::Instr * *const instrRef)
14402
14402
currentBlock->next,
14403
14403
hoistBlock,
14404
14404
hoistInfo.IndexSym(),
14405
- hoistInfo.IndexValueNumber());
14405
+ hoistInfo.IndexValueNumber(),
14406
+ true);
14406
14407
it.IsValid();
14407
14408
it.MoveNext())
14408
14409
{
@@ -14670,7 +14671,7 @@ GlobOpt::OptArraySrc(IR::Instr * *const instrRef)
14670
14671
Assert(!hoistInfo.Loop() || hoistBlock != currentBlock);
14671
14672
if(hoistBlock != currentBlock)
14672
14673
{
14673
- for(InvariantBlockBackwardIterator it(this, currentBlock->next, hoistBlock, nullptr);
14674
+ for(InvariantBlockBackwardIterator it(this, currentBlock->next, hoistBlock, nullptr, InvalidValueNumber, true );
14674
14675
it.IsValid();
14675
14676
it.MoveNext())
14676
14677
{
@@ -17116,12 +17117,15 @@ InvariantBlockBackwardIterator::InvariantBlockBackwardIterator(
17116
17117
BasicBlock *const exclusiveBeginBlock,
17117
17118
BasicBlock *const inclusiveEndBlock,
17118
17119
StackSym *const invariantSym,
17119
- const ValueNumber invariantSymValueNumber)
17120
+ const ValueNumber invariantSymValueNumber,
17121
+ bool followFlow)
17120
17122
: globOpt(globOpt),
17121
17123
exclusiveEndBlock(inclusiveEndBlock->prev),
17122
17124
invariantSym(invariantSym),
17123
17125
invariantSymValueNumber(invariantSymValueNumber),
17124
- block(exclusiveBeginBlock)
17126
+ block(exclusiveBeginBlock),
17127
+ blockBV(globOpt->tempAlloc),
17128
+ followFlow(followFlow)
17125
17129
#if DBG
17126
17130
,
17127
17131
inclusiveEndBlock(inclusiveEndBlock)
@@ -17159,6 +17163,11 @@ InvariantBlockBackwardIterator::MoveNext()
17159
17163
break;
17160
17164
}
17161
17165
17166
+ if (!this->UpdatePredBlockBV())
17167
+ {
17168
+ continue;
17169
+ }
17170
+
17162
17171
if(block->isDeleted)
17163
17172
{
17164
17173
continue;
@@ -17186,6 +17195,28 @@ InvariantBlockBackwardIterator::MoveNext()
17186
17195
}
17187
17196
}
17188
17197
17198
+ bool
17199
+ InvariantBlockBackwardIterator::UpdatePredBlockBV()
17200
+ {
17201
+ if (!this->followFlow)
17202
+ {
17203
+ return true;
17204
+ }
17205
+
17206
+ // Track blocks we've visited to ensure that we only iterate over predecessor blocks
17207
+ if (!this->blockBV.IsEmpty() && !this->blockBV.Test(this->block->GetBlockNum()))
17208
+ {
17209
+ return false;
17210
+ }
17211
+
17212
+ FOREACH_SLISTBASECOUNTED_ENTRY(FlowEdge*, edge, this->block->GetPredList())
17213
+ {
17214
+ this->blockBV.Set(edge->GetPred()->GetBlockNum());
17215
+ } NEXT_SLISTBASECOUNTED_ENTRY;
17216
+
17217
+ return true;
17218
+ }
17219
+
17189
17220
BasicBlock *
17190
17221
InvariantBlockBackwardIterator::Block() const
17191
17222
{
0 commit comments