Skip to content

Commit 6de38e3

Browse files
committed
Fix blocksplitter for trivial conditional branches
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 <ymanton@ca.ibm.com>
1 parent 6ffc9ba commit 6de38e3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

compiler/optimizer/LocalOpts.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -6695,6 +6695,15 @@ TR::Block *TR_BlockSplitter::splitBlock(TR::Block *pred, TR_LinkHeadAndTail<Bloc
66956695
newBlock->append(TR::TreeTop::create(comp(), TR::Node::create(lastRealNode, TR::Goto, 0, nextTree)));
66966696
cfg->addEdge(cloneEnd, newBlock);
66976697
cfg->addEdge(newBlock, nextTree->getNode()->getBlock());
6698+
// The branch target may be the fall-through path. If so, since we're redirecting the fall-through path to a goto block
6699+
// and removing the single edge that represents both the fall-through and branch paths, we should also redirect the branch
6700+
// to the goto block.
6701+
if (lastRealNode->getBranchDestination()->getNode()->getBlock()->getNumber() == nextTree->getNode()->getBlock()->getNumber())
6702+
{
6703+
if (trace())
6704+
traceMsg(comp(), " Redirecting branch %d->%d to %d\n", cloneEnd->getNumber(), nextTree->getNode()->getBlock()->getNumber(), newBlock->getNumber());
6705+
lastRealNode->setBranchDestination(newBlock->getEntry());
6706+
}
66986707
cfg->removeEdge(cloneEnd, nextTree->getNode()->getBlock());
66996708

67006709
if (trace())

0 commit comments

Comments
 (0)