[PATCH] D69852: [JumpThreading] Factor out code to merge basic blocks (NFC)

Wei Mi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 09:05:36 PST 2019


wmi added a comment.

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



================
Comment at: llvm/lib/Transforms/Scalar/JumpThreading.cpp:1884-1887
+  if (BasicBlock *SinglePred = BB->getSinglePredecessor()) {
+    const Instruction *TI = SinglePred->getTerminator();
+    if (!TI->isExceptionalTerminator() && TI->getNumSuccessors() == 1 &&
+        SinglePred != BB && !hasAddressTakenAndUsed(BB)) {
----------------
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;
......
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69852/new/

https://reviews.llvm.org/D69852





More information about the llvm-commits mailing list