aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/MemCpyOptimizer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/Scalar/MemCpyOptimizer.cpp')
-rw-r--r--lib/Transforms/Scalar/MemCpyOptimizer.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 6f93e326ba..4c487e0a34 100644
--- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -762,6 +762,14 @@ bool MemCpyOpt::processMemCpy(MemCpyInst *M) {
ConstantInt *CopySize = dyn_cast<ConstantInt>(M->getLength());
if (CopySize == 0 || M->isVolatile()) return false;
+ // If the source and destination of the memcpy are the same, then zap it.
+ if (M->getSource() == M->getDest()) {
+ MD->removeInstruction(M);
+ M->eraseFromParent();
+ return false;
+ }
+
+
// The are two possible optimizations we can do for memcpy:
// a) memcpy-memcpy xform which exposes redundance for DSE.
// b) call-memcpy xform for return slot optimization.
@@ -773,10 +781,11 @@ bool MemCpyOpt::processMemCpy(MemCpyInst *M) {
return processMemCpyMemCpyDependence(M, MDep, CopySize->getZExtValue());
if (CallInst *C = dyn_cast<CallInst>(DepInfo.getInst())) {
- bool changed = performCallSlotOptzn(M, M->getDest(), M->getSource(),
- CopySize->getZExtValue(), C);
- if (changed) M->eraseFromParent();
- return changed;
+ if (performCallSlotOptzn(M, M->getDest(), M->getSource(),
+ CopySize->getZExtValue(), C)) {
+ M->eraseFromParent();
+ return true;
+ }
}
return false;
}