From b63ba73b1b97e717e04eb8be5f7afc7b2f5ef1ea Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 30 Nov 2010 19:12:10 +0000 Subject: enhance isRemovable to refuse to delete volatile mem transfers now that DSE hacks on them. This fixes a regression I introduced, by generalizing DSE to hack on transfers. llvm-svn: 120445 --- .../lib/Transforms/Scalar/DeadStoreElimination.cpp | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index cb4d482a634..d05f57f0d02 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -152,12 +152,27 @@ getLocForWrite(Instruction *Inst, AliasAnalysis &AA) { /// isRemovable - If the value of this instruction and the memory it writes to /// is unused, may we delete this instruction? static bool isRemovable(Instruction *I) { - assert(hasMemoryWrite(I)); - if (IntrinsicInst *II = dyn_cast(I)) - return II->getIntrinsicID() != Intrinsic::lifetime_end; + // Don't remove volatile stores. if (StoreInst *SI = dyn_cast(I)) return !SI->isVolatile(); - return true; + + IntrinsicInst *II = cast(I); + switch (II->getIntrinsicID()) { + default: assert(0 && "doesn't pass 'hasMemoryWrite' predicate"); + case Intrinsic::lifetime_end: + // Never remove dead lifetime_end's, e.g. because it is followed by a + // free. + return false; + case Intrinsic::init_trampoline: + // Always safe to remove init_trampoline. + return true; + + case Intrinsic::memset: + case Intrinsic::memmove: + case Intrinsic::memcpy: + // Don't remove volatile memory intrinsics. + return !cast(II)->isVolatile(); + } } /// getPointerOperand - Return the pointer that is being written to. -- cgit v1.2.3