[llvm-commits] [llvm] r115305 - /llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Eric Christopher echristo at apple.com
Fri Oct 1 02:02:05 PDT 2010


Author: echristo
Date: Fri Oct  1 04:02:05 2010
New Revision: 115305

URL: http://llvm.org/viewvc/llvm-project?rev=115305&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp?rev=115305&r1=115304&r2=115305&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp Fri Oct  1 04:02:05 2010
@@ -697,13 +697,18 @@
                                  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);
   





More information about the llvm-commits mailing list