[llvm-branch-commits] [llvm] 9f17dab - [SimplifyCFG] Teach simplifyIndirectBr() to preserve DomTree

Roman Lebedev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Dec 31 16:30:33 PST 2020


Author: Roman Lebedev
Date: 2021-01-01T03:25:23+03:00
New Revision: 9f17dab1f48eed788d29e4c6f045e64b0679b3a9

URL: https://github.com/llvm/llvm-project/commit/9f17dab1f48eed788d29e4c6f045e64b0679b3a9
DIFF: https://github.com/llvm/llvm-project/commit/9f17dab1f48eed788d29e4c6f045e64b0679b3a9.diff

LOG: [SimplifyCFG] Teach simplifyIndirectBr() to preserve DomTree

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/test/Transforms/SimplifyCFG/indirectbr.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index d081908c49e9..1fd2956fac51 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -6148,10 +6148,13 @@ bool SimplifyCFGOpt::simplifyIndirectBr(IndirectBrInst *IBI) {
   bool Changed = false;
 
   // Eliminate redundant destinations.
+  std::vector<DominatorTree::UpdateType> Updates;
   SmallPtrSet<Value *, 8> Succs;
   for (unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
     BasicBlock *Dest = IBI->getDestination(i);
     if (!Dest->hasAddressTaken() || !Succs.insert(Dest).second) {
+      if (!Dest->hasAddressTaken())
+        Updates.push_back({DominatorTree::Delete, BB, Dest});
       Dest->removePredecessor(BB);
       IBI->removeDestination(i);
       --i;
@@ -6160,6 +6163,10 @@ bool SimplifyCFGOpt::simplifyIndirectBr(IndirectBrInst *IBI) {
     }
   }
 
+  if (DTU)
+    DTU->applyUpdatesPermissive(Updates);
+  Updates.clear();
+
   if (IBI->getNumDestinations() == 0) {
     // If the indirectbr has no successors, change it to unreachable.
     new UnreachableInst(IBI->getContext(), IBI);

diff  --git a/llvm/test/Transforms/SimplifyCFG/indirectbr.ll b/llvm/test/Transforms/SimplifyCFG/indirectbr.ll
index 67e23d2fe935..52ef6b77166c 100644
--- a/llvm/test/Transforms/SimplifyCFG/indirectbr.ll
+++ b/llvm/test/Transforms/SimplifyCFG/indirectbr.ll
@@ -1,4 +1,4 @@
-; RUN: opt -S -simplifycfg < %s | FileCheck %s
+; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 < %s | FileCheck %s
 
 ; SimplifyCFG should eliminate redundant indirectbr edges.
 


        


More information about the llvm-branch-commits mailing list