This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by kazu on Nov 5 2019, 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.Nov 5 2019, 8:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 5 2019, 8:23 AM
Herald added subscribers: jfb, hiraditya. · View Herald Transcript
wmi accepted this revision.Nov 5 2019, 8:52 AM

LGTM.

This revision is now accepted and ready to land.Nov 5 2019, 8:52 AM
wmi added a comment.Nov 5 2019, 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.Nov 5 2019, 9:36 AM

I've incorporated the feedback from wmi.

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

LGTM.

This revision was automatically updated to reflect the committed changes.