[llvm-branch-commits] [llvm] 2b437fc - [SimplifyCFG] SwitchToLookupTable(): switch to non-permissive DomTree updates

Roman Lebedev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 5 14:57:03 PST 2021


Author: Roman Lebedev
Date: 2021-01-06T01:52:38+03:00
New Revision: 2b437fcd479befb96bd61e71c4de8143bd861a48

URL: https://github.com/llvm/llvm-project/commit/2b437fcd479befb96bd61e71c4de8143bd861a48
DIFF: https://github.com/llvm/llvm-project/commit/2b437fcd479befb96bd61e71c4de8143bd861a48.diff

LOG: [SimplifyCFG] SwitchToLookupTable(): switch to non-permissive DomTree updates

... which requires not deleting a DomTree edge that we just deleted.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index dc931557ebb6..a433d04f2422 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -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 
diff erent 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)


        


More information about the llvm-branch-commits mailing list