diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2014-02-06 06:29:19 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2014-02-06 06:29:19 +0000 |
commit | 44e40408eebdd38831501fc2fab59d550e951808 (patch) | |
tree | ac922edd0cba6bb8000e4635f02bc2adf2fc569e /lib | |
parent | a4f328f68b83dd5fc8387523f0df956816c53384 (diff) | |
download | llvm-44e40408eebdd38831501fc2fab59d550e951808.tar.gz llvm-44e40408eebdd38831501fc2fab59d550e951808.tar.bz2 llvm-44e40408eebdd38831501fc2fab59d550e951808.tar.xz |
A memcpy out of an fresh alloca is a no-op, delete it. Patch by Patrick Walton!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200907 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/MemCpyOptimizer.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp index 3c24e6d364..6619d54288 100644 --- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -843,9 +843,12 @@ bool MemCpyOpt::processMemCpy(MemCpyInst *M) { ConstantInt *CopySize = dyn_cast<ConstantInt>(M->getLength()); if (CopySize == 0) return false; - // The are two possible optimizations we can do for memcpy: + // The are three possible optimizations we can do for memcpy: // a) memcpy-memcpy xform which exposes redundance for DSE. // b) call-memcpy xform for return slot optimization. + // c) memcpy from freshly alloca'd space copies undefined data, and we can + // therefore eliminate the memcpy in favor of the data that was already + // at the destination. MemDepResult DepInfo = MD->getDependency(M); if (DepInfo.isClobber()) { if (CallInst *C = dyn_cast<CallInst>(DepInfo.getInst())) { @@ -865,6 +868,13 @@ bool MemCpyOpt::processMemCpy(MemCpyInst *M) { if (SrcDepInfo.isClobber()) { if (MemCpyInst *MDep = dyn_cast<MemCpyInst>(SrcDepInfo.getInst())) return processMemCpyMemCpyDependence(M, MDep, CopySize->getZExtValue()); + } else if (SrcDepInfo.isDef()) { + if (isa<AllocaInst>(SrcDepInfo.getInst())) { + MD->removeInstruction(M); + M->eraseFromParent(); + ++NumMemCpyInstr; + return true; + } } return false; |