Skip to content

Commit

Permalink
Move removal of exception edges to before collecting fixable predeces…
Browse files Browse the repository at this point in the history
…sors

Blocks could have been removed when the exception edges
of an empty goto block are removed. The removal should
take place before the IN edges are saved in `fixablePreds`.

Fixes: eclipse-openj9/openj9#15305

Signed-off-by: Annabelle Huo <Annabelle.Huo@ibm.com>
  • Loading branch information
a7ehuo committed Jun 21, 2022
1 parent 81e9c1c commit 4cf26fa
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions compiler/optimizer/LocalOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3376,7 +3376,6 @@ int32_t TR_EliminateRedundantGotos::process(TR::TreeTop *startTree, TR::TreeTop
firstNonFenceTree = firstNonFenceTree->getNextRealTreeTop();
}


bool containsTreesOtherThanGoto = false;
if (firstNonFenceTree != lastNonFenceTree &&
!emptyBlock)
Expand Down Expand Up @@ -3440,6 +3439,26 @@ int32_t TR_EliminateRedundantGotos::process(TR::TreeTop *startTree, TR::TreeTop
if (destBlock == block)
continue; // No point trying to "update" predecessors

if (!containsTreesOtherThanGoto && !block->getExceptionSuccessors().empty())
{
// Structure repair doesn't deal well with exception successors in this case.
if (!performTransformation(comp(), "%sRemoving exception successor edges for block_%d\n", optDetailString(), block->getNumber()))
continue; // The exception successors remain, so skip this block

TR::CFGEdgeList &excSuccs = block->getExceptionSuccessors();
while (!excSuccs.empty())
{
if (trace())
{
TR::Block *from = excSuccs.front()->getFrom()->asBlock();
TR::Block *to = excSuccs.front()->getTo()->asBlock();
traceMsg(comp(), "Remove exception edge: block_%d (isValid %d) -> block_%d (isValid %d)\n", from->getNumber(), from->isValid(), to->getNumber(), to->isValid());
}

cfg->removeEdge(excSuccs.front());
}
}

TR::CFGEdgeList fixablePreds(comp()->trMemory()->currentStackRegion());
auto preds = block->getPredecessors();
for (auto inEdge = preds.begin(); inEdge != preds.end(); ++inEdge)
Expand Down Expand Up @@ -3527,19 +3546,6 @@ int32_t TR_EliminateRedundantGotos::process(TR::TreeTop *startTree, TR::TreeTop
//destBlock->setEntry(block->getEntry());
//destBlock->setExit(block->getExit());
}
else
{
if (!block->getExceptionSuccessors().empty())
{
// A block with a goto, only a goto and nothing but the goto needs
// no exception successors (removing them is a good idea in general, but
// structure repair below specifically does not like such nasty nasty
// goto blocks)
//
for (auto edge = block->getExceptionSuccessors().begin(); edge != block->getExceptionSuccessors().end();)
cfg->removeEdge(*(edge++));
}
}

if (emptyBlock &&
!performTransformation(comp(), "%sRemoving empty block_%d with BBStart %p\n", optDetailString(), block->getNumber(), block->getEntry()->getNode()))
Expand Down

0 comments on commit 4cf26fa

Please sign in to comment.