Skip to content

Commit

Permalink
Fix blocksplitter for trivial conditional branches
Browse files Browse the repository at this point in the history
Certain conditional branches can be made trivial by earlier opts. For
these the branch target may be the fall-through path. If so, since we're
redirecting the fall-through path to a goto block and removing the
single edge that represents both the fall-through and branch paths, we
should also redirect the branch to the goto block.

Signed-off-by: Younes Manton <[email protected]>
  • Loading branch information
ymanton committed Sep 17, 2024
1 parent 6ffc9ba commit 6de38e3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compiler/optimizer/LocalOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6695,6 +6695,15 @@ TR::Block *TR_BlockSplitter::splitBlock(TR::Block *pred, TR_LinkHeadAndTail<Bloc
newBlock->append(TR::TreeTop::create(comp(), TR::Node::create(lastRealNode, TR::Goto, 0, nextTree)));
cfg->addEdge(cloneEnd, newBlock);
cfg->addEdge(newBlock, nextTree->getNode()->getBlock());
// The branch target may be the fall-through path. If so, since we're redirecting the fall-through path to a goto block
// and removing the single edge that represents both the fall-through and branch paths, we should also redirect the branch
// to the goto block.
if (lastRealNode->getBranchDestination()->getNode()->getBlock()->getNumber() == nextTree->getNode()->getBlock()->getNumber())
{
if (trace())
traceMsg(comp(), " Redirecting branch %d->%d to %d\n", cloneEnd->getNumber(), nextTree->getNode()->getBlock()->getNumber(), newBlock->getNumber());
lastRealNode->setBranchDestination(newBlock->getEntry());
}
cfg->removeEdge(cloneEnd, nextTree->getNode()->getBlock());

if (trace())
Expand Down

0 comments on commit 6de38e3

Please sign in to comment.