From db1176ce66cf276b45ac3b90ea6b5ce62de56be7 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Sat, 5 Feb 2022 02:29:28 +0300 Subject: Revert "[SimplifyCFG] `markAliveBlocks()`: recognize that normal dest of `invoke`d `noreturn` function is `unreachable`" The normal destination may have other uses. This reverts commit 598833c987593ce192fa827f162cae8c867c9d43. --- llvm/lib/Transforms/Utils/Local.cpp | 39 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'llvm/lib/Transforms/Utils/Local.cpp') diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 58eb7d4..9a10535 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2349,32 +2349,19 @@ static bool markAliveBlocks(Function &F, isa(Callee)) { changeToUnreachable(II, false, DTU); Changed = true; - } else { - if (II->doesNotReturn()) { - // If we found an invoke of a no-return function, - // insert an unreachable instruction after it (on the normal dest). - // Make sure there isn't *already* one there though. - Instruction *FirstNormalInst = &II->getNormalDest()->front(); - if (!isa(FirstNormalInst)) { - // Don't insert a call to llvm.trap right before the unreachable. - changeToUnreachable(FirstNormalInst, false, DTU); - Changed = true; - } - } - if (II->doesNotThrow() && canSimplifyInvokeNoUnwind(&F)) { - if (II->use_empty() && II->onlyReadsMemory()) { - // jump to the normal destination branch. - BasicBlock *NormalDestBB = II->getNormalDest(); - BasicBlock *UnwindDestBB = II->getUnwindDest(); - BranchInst::Create(NormalDestBB, II); - UnwindDestBB->removePredecessor(II->getParent()); - II->eraseFromParent(); - if (DTU) - DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}}); - } else - changeToCall(II, DTU); - Changed = true; - } + } else if (II->doesNotThrow() && canSimplifyInvokeNoUnwind(&F)) { + if (II->use_empty() && II->onlyReadsMemory()) { + // jump to the normal destination branch. + BasicBlock *NormalDestBB = II->getNormalDest(); + BasicBlock *UnwindDestBB = II->getUnwindDest(); + BranchInst::Create(NormalDestBB, II); + UnwindDestBB->removePredecessor(II->getParent()); + II->eraseFromParent(); + if (DTU) + DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}}); + } else + changeToCall(II, DTU); + Changed = true; } } else if (auto *CatchSwitch = dyn_cast(Terminator)) { // Remove catchpads which cannot be reached. -- cgit v1.1