From 93a1642763c9105f0e7d8388dcd7dfc6e2bae630 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Fri, 2 Jul 2021 17:17:47 +0300 Subject: [PATCH] Revert "[NFCI][InstCombine] visitUnreachableInst(): iteratively erase instructions leading to unreachable" This reverts commit d9d65527c289fb27a9f92f150723bbb3c58e413f. --- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index d29527f..8f75a7ea 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2874,24 +2874,23 @@ Instruction *InstCombinerImpl::visitUnreachableInst(UnreachableInst &I) { // Try to remove the previous instruction if it must lead to unreachable. // This includes instructions like stores and "llvm.assume" that may not get // removed by simple dead code elimination. - while (Instruction *Prev = I.getPrevNonDebugInstruction()) { - if (Prev->isEHPad() || !isGuaranteedToTransferExecutionToSuccessor(Prev)) - return nullptr; // Can not drop any more instructions. We're done here. + Instruction *Prev = I.getPrevNonDebugInstruction(); + if (Prev && !Prev->isEHPad() && + isGuaranteedToTransferExecutionToSuccessor(Prev)) { // Temporarily disable removal of volatile stores preceding unreachable, // pending a potential LangRef change permitting volatile stores to trap. // TODO: Either remove this code, or properly integrate the check into // isGuaranteedToTransferExecutionToSuccessor(). if (auto *SI = dyn_cast(Prev)) if (SI->isVolatile()) - return nullptr; // Can not drop this instruction. We're done here. + return nullptr; // A value may still have uses before we process it here (for example, in // another unreachable block), so convert those to poison. replaceInstUsesWith(*Prev, PoisonValue::get(Prev->getType())); eraseInstFromFunction(*Prev); + return &I; } - assert(I.getParent()->sizeWithoutDebug() == 1 && "The block is now empty."); - // FIXME: recurse into unconditional predecessors? return nullptr; } -- 2.7.4