From 729e18cbf498fb9b95fd672691ee8c7b7926f674 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Wed, 19 May 2021 11:31:53 +0300 Subject: [PATCH] [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. --- llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp index 97ccfc3..58d648b 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 @@ -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; } -- 2.7.4