[PATCH] D105339: [InstCombine] visitUnreachableInst(): iteratively erase instructions leading to unreachable
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 2 07:17:34 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd9d65527c289: [NFCI][InstCombine] visitUnreachableInst(): iteratively erase instructions… (authored by lebedev.ri).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105339/new/
https://reviews.llvm.org/D105339
Files:
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2874,23 +2874,24 @@
// 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.
- Instruction *Prev = I.getPrevNonDebugInstruction();
- if (Prev && !Prev->isEHPad() &&
- isGuaranteedToTransferExecutionToSuccessor(Prev)) {
+ while (Instruction *Prev = I.getPrevNonDebugInstruction()) {
+ if (Prev->isEHPad() || !isGuaranteedToTransferExecutionToSuccessor(Prev))
+ return nullptr; // Can not drop any more instructions. We're done here.
// 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<StoreInst>(Prev))
if (SI->isVolatile())
- return nullptr;
+ return nullptr; // Can not drop this instruction. We're done here.
// 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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105339.356166.patch
Type: text/x-patch
Size: 1744 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210702/fe16d020/attachment.bin>
More information about the llvm-commits
mailing list