remove a pointless restriction from memcpyopt. It was
refusing to optimize two memcpy's like this:
copy A <- B
copy C <- A
if it couldn't prove that noalias(B,C). We can eliminate
the copy by producing a memmove instead of memcpy.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119694 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index ea29fca..9c16ae4 100644
--- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -688,11 +688,14 @@
if (DepSize < MSize)
return false;
- // Finally, we have to make sure that the dest of the second does not
- // alias the source of the first.
+ Intrinsic::ID ResultFn = Intrinsic::memcpy;
+
+ // If the dest of the second might alias the source of the first, then the
+ // source and dest might overlap. We still want to eliminate the intermediate
+ // value, but we have to generate a memmove instead of memcpy.
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
if (!AA.isNoAlias(M->getRawDest(), MSize, MDep->getRawSource(), DepSize))
- return false;
+ ResultFn = Intrinsic::memmove;
// If all checks passed, then we can transform these memcpy's
const Type *ArgTys[3] = {
@@ -702,7 +705,7 @@
};
Function *MemCpyFun =
Intrinsic::getDeclaration(M->getParent()->getParent()->getParent(),
- M->getIntrinsicID(), ArgTys, 3);
+ ResultFn, ArgTys, 3);
// Make sure to use the lesser of the alignment of the source and the dest
// since we're changing where we're reading from, but don't want to increase