[SimplifyCFG] SwitchToLookupTable(): switch to non-permissive DomTree updates
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 5 Jan 2021 16:59:16 +0000 (19:59 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 5 Jan 2021 22:52:38 +0000 (01:52 +0300)
... which requires not deleting a DomTree edge that we just deleted.

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

index dc93155..a433d04 100644 (file)
@@ -5827,7 +5827,6 @@ static void reuseTableCompare(
 /// If the switch is only used to initialize one or more phi nodes in a common
 /// successor block with different constant values, replace the switch with
 /// lookup tables.
-// FIXME: switch to non-permissive DomTreeUpdater::applyUpdates().
 static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
                                 DomTreeUpdater *DTU, const DataLayout &DL,
                                 const TargetTransformInfo &TTI) {
@@ -6063,17 +6062,22 @@ static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
   }
 
   // Remove the switch.
+  SmallSetVector<BasicBlock *, 8> RemovedSuccessors;
   for (unsigned i = 0, e = SI->getNumSuccessors(); i < e; ++i) {
     BasicBlock *Succ = SI->getSuccessor(i);
 
     if (Succ == SI->getDefaultDest())
       continue;
     Succ->removePredecessor(BB);
-    Updates.push_back({DominatorTree::Delete, BB, Succ});
+    RemovedSuccessors.insert(Succ);
   }
   SI->eraseFromParent();
-  if (DTU)
-    DTU->applyUpdatesPermissive(Updates);
+
+  if (DTU) {
+    for (BasicBlock *RemovedSuccessor : RemovedSuccessors)
+      Updates.push_back({DominatorTree::Delete, BB, RemovedSuccessor});
+    DTU->applyUpdates(Updates);
+  }
 
   ++NumLookupTables;
   if (NeedMask)