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 | 993849490ee29c8704c983caa0743cb0ab52b836 (patch) | |
tree | 0fb884d99049452631f9464782c7163039994078 /llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp | |
parent | f1aab4502ef9aed1202a1e287011ef95235977ff (diff) | |
download | bcm5719-llvm-993849490ee29c8704c983caa0743cb0ab52b836.tar.gz bcm5719-llvm-993849490ee29c8704c983caa0743cb0ab52b836.zip |
A memcpy out of an fresh alloca is a no-op, delete it. Patch by Patrick Walton!
llvm-svn: 200907
Diffstat (limited to 'llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp index 3c24e6d3643..6619d542885 100644 --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/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; |