[llvm-commits] [llvm] r164561 - in /llvm/trunk: lib/Transforms/Scalar/DeadStoreElimination.cpp test/Transforms/DeadStoreElimination/libcalls.ll
Nick Lewycky
nlewycky at google.com
Mon Sep 24 16:49:13 PDT 2012
On 24 September 2012 16:41, Jim Grosbach <grosbach at apple.com> wrote:
>
> On Sep 24, 2012, at 3:09 PM, Nick Lewycky <nicholas at mxc.ca> wrote:
>
> > Author: nicholas
> > Date: Mon Sep 24 17:09:10 2012
> > New Revision: 164561
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=164561&view=rev
> > Log:
> > Teach DSE that strcpy, strncpy, strcat and strncat are all stores which
> may be
> > dead.
> >
> > Added:
> > llvm/trunk/test/Transforms/DeadStoreElimination/libcalls.ll
> > Modified:
> > llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
> >
>
> > @@ -208,7 +229,8 @@
> > /// instruction if any.
> > static AliasAnalysis::Location
> > getLocForRead(Instruction *Inst, AliasAnalysis &AA) {
> > - assert(hasMemoryWrite(Inst) && "Unknown instruction case");
> > + assert(hasMemoryWrite(Inst, AA.getTargetLibraryInfo()) &&
> > + "Unknown instruction case");
> >
> > // The only instructions that both read and write are the mem transfer
> > // instructions (memcpy/memmove).
> > @@ -225,23 +247,29 @@
> > if (StoreInst *SI = dyn_cast<StoreInst>(I))
> > return SI->isUnordered();
> >
> > - IntrinsicInst *II = cast<IntrinsicInst>(I);
> > - switch (II->getIntrinsicID()) {
> > - default: llvm_unreachable("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;
> > + if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
> > + switch (II->getIntrinsicID()) {
> > + default: llvm_unreachable("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<MemIntrinsic>(II)->isVolatile();
> > + case Intrinsic::memset:
> > + case Intrinsic::memmove:
> > + case Intrinsic::memcpy:
> > + // Don't remove volatile memory intrinsics.
> > + return !cast<MemIntrinsic>(II)->isVolatile();
> > + }
> > }
> > +
> > + if (CallSite CS = I) // If we assume hasMemoryWrite(I) is true,
> > + return true; // then there's nothing left to check.
>
> warning: unused
> variable 'CS' [-Wunused-variable]
> if (CallSite CS = I) // If we assume hasMemoryWrite(I) is true,
> ^
>
Thanks! Fixed in r164576.
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120924/c16830f7/attachment.html>
More information about the llvm-commits
mailing list