aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorNick Desaulniers <ndesaulniers@google.com>2022-07-19 14:59:07 -0700
committerNick Desaulniers <ndesaulniers@google.com>2022-07-19 15:03:27 -0700
commit1cf6b93df168fea81e3ca7c6c3c9fcaaf82c7785 (patch)
tree2388a4687fddef01535424fcd8bc5abdd8444ad5 /llvm/lib/Transforms/Utils/Local.cpp
parent6d8438314fa69f8c978a710c6ef1304bfe9c3451 (diff)
downloadllvm-1cf6b93df168fea81e3ca7c6c3c9fcaaf82c7785.zip
llvm-1cf6b93df168fea81e3ca7c6c3c9fcaaf82c7785.tar.gz
llvm-1cf6b93df168fea81e3ca7c6c3c9fcaaf82c7785.tar.bz2
Revert "[Local] Allow creating callbr with duplicate successors"
This reverts commit 08860f525a2363ccd697ebb3ff59769e37b1be21. Crashes during PPC64LE linux kernel builds as reported by @nathanchance. https://reviews.llvm.org/D129997#3663632
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index fbae547..b203259 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1089,6 +1089,18 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
}
}
+ // We cannot fold the block if it's a branch to an already present callbr
+ // successor because that creates duplicate successors.
+ for (BasicBlock *PredBB : predecessors(BB)) {
+ if (auto *CBI = dyn_cast<CallBrInst>(PredBB->getTerminator())) {
+ if (Succ == CBI->getDefaultDest())
+ return false;
+ for (unsigned i = 0, e = CBI->getNumIndirectDests(); i != e; ++i)
+ if (Succ == CBI->getIndirectDest(i))
+ return false;
+ }
+ }
+
LLVM_DEBUG(dbgs() << "Killing Trivial BB: \n" << *BB);
SmallVector<DominatorTree::UpdateType, 32> Updates;