Page MenuHomePhabricator

[JumpThreading] Factor out code to merge basic blocks (NFC)
ClosedPublic

Authored by kazu on Tue, Nov 5, 8:23 AM.

Details

Summary

This patch factors out code to merge a basic block with its sole
successor -- partly for readability and partly to facilitate an
upcoming patch of my own.

Diff Detail

Event Timeline

kazu created this revision.Tue, Nov 5, 8:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptTue, Nov 5, 8:23 AM
Herald added subscribers: jfb, hiraditya. · View Herald Transcript
wmi accepted this revision.Tue, Nov 5, 8:52 AM

LGTM.

This revision is now accepted and ready to land.Tue, Nov 5, 8:52 AM
wmi added a comment.Tue, Nov 5, 8:58 AM

Sorry, there is a little more refactoring which could be done.

llvm/lib/Transforms/Scalar/JumpThreading.cpp
1884–1887

It is better to have some early return to handle the cases in which we cannot merge.

BasicBlock *SinglePred = BB->getSinglePredecessor()
if (!SinglePred)
  return false;
const Instruction *TI = SinglePred->getTerminator();
if (TI->isExceptionalTerminator() || TI->getNumSuccessors() != 1 ||
        SinglePred == BB || hasAddressTakenAndUsed(BB))
  return false;
......
kazu updated this revision to Diff 227903.Tue, Nov 5, 9:36 AM

I've incorporated the feedback from wmi.

kazu marked an inline comment as done.Tue, Nov 5, 9:38 AM
wmi accepted this revision.Tue, Nov 5, 9:46 AM

LGTM.

This revision was automatically updated to reflect the committed changes.