summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2014-03-26 23:45:15 +0000
committerNick Lewycky <nicholas@mxc.ca>2014-03-26 23:45:15 +0000
commit77d5fb40c8f71a5bef45e7ad8aeb8a444a6e3df4 (patch)
tree56566888a6737d8ba814daad1bd54f0da687d0a9 /llvm/lib
parent7790cf88e0119f3c16062700587d9589c57f10a1 (diff)
downloadbcm5719-llvm-77d5fb40c8f71a5bef45e7ad8aeb8a444a6e3df4.tar.gz
bcm5719-llvm-77d5fb40c8f71a5bef45e7ad8aeb8a444a6e3df4.zip
Treat lifetime.start'd memory like we treat freshly alloca'd memory. Patch by Björn Steinbrink!
llvm-svn: 204876
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 143ba38ec98..2603c969c5a 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -851,9 +851,9 @@ bool MemCpyOpt::processMemCpy(MemCpyInst *M) {
// 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.
+ // c) memcpy from freshly alloca'd space or space that has just started its
+ // lifetime 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())) {
@@ -874,7 +874,19 @@ bool MemCpyOpt::processMemCpy(MemCpyInst *M) {
if (MemCpyInst *MDep = dyn_cast<MemCpyInst>(SrcDepInfo.getInst()))
return processMemCpyMemCpyDependence(M, MDep, CopySize->getZExtValue());
} else if (SrcDepInfo.isDef()) {
- if (isa<AllocaInst>(SrcDepInfo.getInst())) {
+ Instruction *I = SrcDepInfo.getInst();
+ bool hasUndefContents = false;
+
+ if (isa<AllocaInst>(I)) {
+ hasUndefContents = true;
+ } else if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
+ if (II->getIntrinsicID() == Intrinsic::lifetime_start)
+ if (ConstantInt *LTSize = dyn_cast<ConstantInt>(II->getArgOperand(0)))
+ if (LTSize->getZExtValue() >= CopySize->getZExtValue())
+ hasUndefContents = true;
+ }
+
+ if (hasUndefContents) {
MD->removeInstruction(M);
M->eraseFromParent();
++NumMemCpyInstr;
OpenPOWER on IntegriCloud