aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2021-01-15 20:57:28 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2021-01-15 23:35:57 +0300
commita14c36fe27f5c36de44049237011d140a7277774 (patch)
treeaa489a3a6d878da89f62d759448eb9e2061ba3da /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parentc6654a4cdab4156bae51970fa64993e790fc4adb (diff)
downloadllvm-a14c36fe27f5c36de44049237011d140a7277774.zip
llvm-a14c36fe27f5c36de44049237011d140a7277774.tar.gz
llvm-a14c36fe27f5c36de44049237011d140a7277774.tar.bz2
[SimplifyCFG] switchToSelect(): don't forget to insert DomTree edge iff needed
DestBB might or might not already be a successor of SelectBB, and it wasn't we need to ensure that we record the fact in DomTree. The testcase used to crash in lazy domtree updater mode + non-per-function domtree validity checks disabled.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 4c0427e..559830e 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -5394,20 +5394,25 @@ static void RemoveSwitchAfterSelectConversion(SwitchInst *SI, PHINode *PHI,
Value *SelectValue,
IRBuilder<> &Builder,
DomTreeUpdater *DTU) {
+ std::vector<DominatorTree::UpdateType> Updates;
+
BasicBlock *SelectBB = SI->getParent();
+ BasicBlock *DestBB = PHI->getParent();
+
+ if (!is_contained(predecessors(DestBB), SelectBB))
+ Updates.push_back({DominatorTree::Insert, SelectBB, DestBB});
+ Builder.CreateBr(DestBB);
+
+ // Remove the switch.
+
while (PHI->getBasicBlockIndex(SelectBB) >= 0)
PHI->removeIncomingValue(SelectBB);
PHI->addIncoming(SelectValue, SelectBB);
- Builder.CreateBr(PHI->getParent());
-
- std::vector<DominatorTree::UpdateType> Updates;
-
- // Remove the switch.
for (unsigned i = 0, e = SI->getNumSuccessors(); i < e; ++i) {
BasicBlock *Succ = SI->getSuccessor(i);
- if (Succ == PHI->getParent())
+ if (Succ == DestBB)
continue;
Succ->removePredecessor(SelectBB);
Updates.push_back({DominatorTree::Delete, SelectBB, Succ});