[llvm] 8c2b535 - [NFCI][SimplifyCFG] removeEmptyCleanup(): use DeleteDeadBlock()

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed May 19 04:09:03 PDT 2021


Author: Roman Lebedev
Date: 2021-05-19T14:08:25+03:00
New Revision: 8c2b535d6c38d1a54c5a23301325112f00a341f7

URL: https://github.com/llvm/llvm-project/commit/8c2b535d6c38d1a54c5a23301325112f00a341f7
DIFF: https://github.com/llvm/llvm-project/commit/8c2b535d6c38d1a54c5a23301325112f00a341f7.diff

LOG: [NFCI][SimplifyCFG] removeEmptyCleanup(): use DeleteDeadBlock()

This required some changes to, instead of eagerly making PHI's
in the UnwindDest valid as-if the BB is already not a predecessor,
to be valid while BB is still a predecessor.

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 b0e5e532c12f..e25362c346d6 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -4486,9 +4486,6 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
       Value *SrcVal = DestPN.getIncomingValue(Idx);
       PHINode *SrcPN = dyn_cast<PHINode>(SrcVal);
 
-      // Remove the entry for the block we are deleting.
-      DestPN.removeIncomingValue(Idx, false);
-
       bool NeedPHITranslation = SrcPN && SrcPN->getParent() == BB;
       for (auto *Pred : predecessors(BB)) {
         Value *Incoming =
@@ -4516,12 +4513,15 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
         if (pred != BB)
           PN.addIncoming(&PN, pred);
       PN.moveBefore(InsertPt);
+      // Also, add a dummy incoming value for the original BB itself,
+      // so that the PHI is well-formed until we drop said predecessor.
+      PN.addIncoming(UndefValue::get(PN.getType()), BB);
     }
   }
 
   std::vector<DominatorTree::UpdateType> Updates;
 
-  // We use make_early_inc_range here because we may remove some predecessors.
+  // We use make_early_inc_range here because we will remove all predecessors.
   for (BasicBlock *PredBB : llvm::make_early_inc_range(predecessors(BB))) {
     if (UnwindDest == nullptr) {
       if (DTU) {
@@ -4531,6 +4531,7 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
       removeUnwindEdge(PredBB, DTU);
       ++NumInvokes;
     } else {
+      BB->removePredecessor(PredBB);
       Instruction *TI = PredBB->getTerminator();
       TI->replaceUsesOfWith(BB, UnwindDest);
       if (DTU) {
@@ -4540,12 +4541,10 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
     }
   }
 
-  if (DTU) {
+  if (DTU)
     DTU->applyUpdates(Updates);
-    DTU->deleteBB(BB);
-  } else
-    // The cleanup pad is now unreachable.  Zap it.
-    BB->eraseFromParent();
+
+  DeleteDeadBlock(BB, DTU);
 
   return true;
 }


        


More information about the llvm-commits mailing list