summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/MemCpyOptimizer.cpp
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2010-10-01 09:02:05 +0000
committerEric Christopher <echristo@apple.com>2010-10-01 09:02:05 +0000
commit04fcbf954fef6d9866b5120f406e7401dc9aa29f (patch)
treed1d23d216ca4e0ebe10cb5d4ae72993dd4db176e /lib/Transforms/Scalar/MemCpyOptimizer.cpp
parentb1170f0e62984199596055b2b880d03890d30604 (diff)
downloadllvm-04fcbf954fef6d9866b5120f406e7401dc9aa29f.tar.gz
llvm-04fcbf954fef6d9866b5120f406e7401dc9aa29f.tar.bz2
llvm-04fcbf954fef6d9866b5120f406e7401dc9aa29f.tar.xz
Fix the other half of the alignment changing issue by making sure that the
memcpy alignment is the minimum of the incoming alignments. Fixes PR 8266. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115305 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/MemCpyOptimizer.cpp')
-rw-r--r--lib/Transforms/Scalar/MemCpyOptimizer.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index f94c9e2257..4172b345c6 100644
--- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -697,13 +697,18 @@ bool MemCpyOpt::processMemCpy(MemCpyInst *M) {
M->getParent()->getParent()->getParent(),
M->getIntrinsicID(), ArgTys, 3);
- // Make sure to use the alignment of the source since we're changing the
- // location we're reading from.
+ // 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
+ // the alignment past what can be read from or written to.
// TODO: Is this worth it if we're creating a less aligned memcpy? For
// example we could be moving from movaps -> movq on x86.
+ unsigned Align = std::min(MDep->getAlignmentCst()->getZExtValue(),
+ M->getAlignmentCst()->getZExtValue());
+ LLVMContext &Context = M->getContext();
+ ConstantInt *AlignCI = ConstantInt::get(Type::getInt32Ty(Context), Align);
Value *Args[5] = {
M->getRawDest(), MDep->getRawSource(), M->getLength(),
- MDep->getAlignmentCst(), M->getVolatileCst()
+ AlignCI, M->getVolatileCst()
};
CallInst *C = CallInst::Create(MemCpyFun, Args, Args+5, "", M);