summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorAhmed Bougacha <ahmed.bougacha@gmail.com>2015-05-21 01:43:39 +0000
committerAhmed Bougacha <ahmed.bougacha@gmail.com>2015-05-21 01:43:39 +0000
commit97876fa894222ea2c11923c1dbe2b7647e424fe9 (patch)
tree00a2265729452f775fc0eb805a42b3c9dd0d7a46 /llvm/lib
parent5435aa464a62f4d82fbe643ade6fdcc40acbd141 (diff)
downloadbcm5719-llvm-97876fa894222ea2c11923c1dbe2b7647e424fe9.tar.gz
bcm5719-llvm-97876fa894222ea2c11923c1dbe2b7647e424fe9.zip
[MemCpyOpt] Do move the memset, but look at its dest's dependencies.
In effect a partial revert of r237858, which was a dumb shortcut. Looking at the dependencies of the destination should be the proper fix: if the new memset would depend on anything other than itself, the transformation isn't correct. llvm-svn: 237874
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index a90204d26bd..66d6ac6f3a0 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -859,6 +859,13 @@ bool MemCpyOpt::processMemSetMemCpyDependence(MemCpyInst *MemCpy,
if (MemSet->getDest() != MemCpy->getDest())
return false;
+ // Check that there are no other dependencies on the memset destination.
+ MemDepResult DstDepInfo =
+ MD->getPointerDependencyFrom(AliasAnalysis::getLocationForDest(MemSet),
+ false, MemCpy, MemCpy->getParent());
+ if (DstDepInfo.getInst() != MemSet)
+ return false;
+
// Use the same i8* dest as the memcpy, killing the memset dest if different.
Value *Dest = MemCpy->getRawDest();
Value *DestSize = MemSet->getLength();
@@ -874,7 +881,7 @@ bool MemCpyOpt::processMemSetMemCpyDependence(MemCpyInst *MemCpy,
if (ConstantInt *SrcSizeC = dyn_cast<ConstantInt>(SrcSize))
Align = MinAlign(SrcSizeC->getZExtValue(), DestAlign);
- IRBuilder<> Builder(MemSet);
+ IRBuilder<> Builder(MemCpy);
// If the sizes have different types, zext the smaller one.
if (DestSize->getType() != SrcSize->getType()) {
OpenPOWER on IntegriCloud