diff options
author | Chris Lattner <sabre@nondot.org> | 2010-11-18 08:00:57 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-11-18 08:00:57 +0000 |
commit | 5a7aeaa01904b9b0adf256108f302f8961295754 (patch) | |
tree | d61e12af604ae01207dbf31bdba33fdb64db3bef /lib/Transforms/Scalar/MemCpyOptimizer.cpp | |
parent | 7cac8e1691156f22f2f1def0e82d6374bb2b0f21 (diff) |
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
Diffstat (limited to 'lib/Transforms/Scalar/MemCpyOptimizer.cpp')
-rw-r--r-- | lib/Transforms/Scalar/MemCpyOptimizer.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp index ea29fca346..9c16ae417c 100644 --- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -688,11 +688,14 @@ bool MemCpyOpt::processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep, 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 @@ bool MemCpyOpt::processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep, }; 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 |