[llvm] 729e18c - [NFCI] SimplifyCFGPass: mergeEmptyReturnBlocks(): use DeleteDeadBlocks()

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed May 19 01:32:44 PDT 2021


Author: Roman Lebedev
Date: 2021-05-19T11:32:24+03:00
New Revision: 729e18cbf498fb9b95fd672691ee8c7b7926f674

URL: https://github.com/llvm/llvm-project/commit/729e18cbf498fb9b95fd672691ee8c7b7926f674
DIFF: https://github.com/llvm/llvm-project/commit/729e18cbf498fb9b95fd672691ee8c7b7926f674.diff

LOG: [NFCI] SimplifyCFGPass: mergeEmptyReturnBlocks(): use DeleteDeadBlocks()

In this case, it does the same thing as the original pattern does.

SimplifyCFG has a few lurking miscompilations about deleting blocks that
have their address taken, and consistently using DeleteDeadBlocks() instead
 of a hand-rolled pattern will allow to weed those cases out easierly.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
index 97ccfc3b07822..58d648b61c060 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -42,6 +42,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Scalar/SimplifyCFG.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Transforms/Utils/SimplifyCFGOptions.h"
 #include <utility>
@@ -183,14 +184,10 @@ static bool mergeEmptyReturnBlocks(Function &F, DomTreeUpdater *DTU) {
       Updates.push_back({DominatorTree::Insert, &BB, RetBlock});
   }
 
-  if (DTU) {
+  if (DTU)
     DTU->applyUpdates(Updates);
-    for (auto *BB : DeadBlocks)
-      DTU->deleteBB(BB);
-  } else {
-    for (auto *BB : DeadBlocks)
-      BB->eraseFromParent();
-  }
+
+  DeleteDeadBlocks(DeadBlocks, DTU);
 
   return Changed;
 }


        


More information about the llvm-commits mailing list