[llvm-branch-commits] [llvm] 110b3d7 - [SimplifyCFG] SimplifyEqualityComparisonWithOnlyPredecessor(): switch to non-permissive DomTree updates

Roman Lebedev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jan 4 14:31:56 PST 2021


Author: Roman Lebedev
Date: 2021-01-05T01:26:37+03:00
New Revision: 110b3d7855ef71a7d43a0779b2e1c32e1a31daae

URL: https://github.com/llvm/llvm-project/commit/110b3d7855ef71a7d43a0779b2e1c32e1a31daae
DIFF: https://github.com/llvm/llvm-project/commit/110b3d7855ef71a7d43a0779b2e1c32e1a31daae.diff

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

... which requires not deleting an edge that just got 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 60fa8a876b53..a61e48d84f01 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -872,7 +872,6 @@ static void setBranchWeights(Instruction *I, uint32_t TrueWeight,
 /// also a value comparison with the same value, and if that comparison
 /// determines the outcome of this comparison. If so, simplify TI. This does a
 /// very limited form of jump threading.
-// FIXME: switch to non-permissive DomTreeUpdater::applyUpdates().
 bool SimplifyCFGOpt::SimplifyEqualityComparisonWithOnlyPredecessor(
     Instruction *TI, BasicBlock *Pred, IRBuilder<> &Builder) {
   Value *PredVal = isValueEqualityComparison(Pred->getTerminator());
@@ -988,14 +987,14 @@ bool SimplifyCFGOpt::SimplifyEqualityComparisonWithOnlyPredecessor(
   if (!TheRealDest)
     TheRealDest = ThisDef;
 
-  SmallVector<DominatorTree::UpdateType, 2> Updates;
+  SmallSetVector<BasicBlock *, 2> RemovedSuccs;
 
   // Remove PHI node entries for dead edges.
   BasicBlock *CheckEdge = TheRealDest;
   for (BasicBlock *Succ : successors(TIBB))
     if (Succ != CheckEdge) {
+      RemovedSuccs.insert(Succ);
       Succ->removePredecessor(TIBB);
-      Updates.push_back({DominatorTree::Delete, TIBB, Succ});
     } else
       CheckEdge = nullptr;
 
@@ -1008,8 +1007,13 @@ bool SimplifyCFGOpt::SimplifyEqualityComparisonWithOnlyPredecessor(
                     << "\n");
 
   EraseTerminatorAndDCECond(TI);
-  if (DTU)
-    DTU->applyUpdatesPermissive(Updates);
+  if (DTU) {
+    SmallVector<DominatorTree::UpdateType, 2> Updates;
+    Updates.reserve(RemovedSuccs.size());
+    for (auto *RemovedSucc : RemovedSuccs)
+      Updates.push_back({DominatorTree::Delete, TIBB, RemovedSucc});
+    DTU->applyUpdates(Updates);
+  }
   return true;
 }
 


        


More information about the llvm-branch-commits mailing list