[llvm] r256999 - Fix PR26051: Memcpy optimization should introduce a call to memcpy before the store destination position

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 6 15:50:22 PST 2016


Author: mehdi_amini
Date: Wed Jan  6 17:50:22 2016
New Revision: 256999

URL: http://llvm.org/viewvc/llvm-project?rev=256999&view=rev
Log:
Fix PR26051: Memcpy optimization should introduce a call to memcpy before the store destination position

This is a conservative fix, I expect Amaury to relax this.
Follow-up for r256923

From: Mehdi Amini <mehdi.amini at apple.com>

Modified:
    llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
    llvm/trunk/test/Transforms/MemCpyOpt/fca2memcpy.ll

Modified: llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp?rev=256999&r1=256998&r2=256999&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp Wed Jan  6 17:50:22 2016
@@ -529,11 +529,13 @@ bool MemCpyOpt::processStore(StoreInst *
 
           // We found an instruction that may write to the loaded memory.
           // We can try to promote at this position instead of the store
-          // position if nothing alias the store memory after this.
+          // position if nothing alias the store memory after this and the store
+          // destination is not in the range.
           P = &*I;
           for (; I != E; ++I) {
             MemoryLocation StoreLoc = MemoryLocation::get(SI);
-            if (AA.getModRefInfo(&*I, StoreLoc) != MRI_NoModRef) {
+            if (&*I == SI->getOperand(1) ||
+                AA.getModRefInfo(&*I, StoreLoc) != MRI_NoModRef) {
               P = nullptr;
               break;
             }

Modified: llvm/trunk/test/Transforms/MemCpyOpt/fca2memcpy.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MemCpyOpt/fca2memcpy.ll?rev=256999&r1=256998&r2=256999&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/MemCpyOpt/fca2memcpy.ll (original)
+++ llvm/trunk/test/Transforms/MemCpyOpt/fca2memcpy.ll Wed Jan  6 17:50:22 2016
@@ -72,3 +72,17 @@ define void @copyalias(%S* %src, %S* %ds
   store %S %2, %S* %dst
   ret void
 }
+
+
+; The GEP is present after the aliasing store, preventing to move the memcpy before
+; (without further analysis/transformation)
+define void @copyaliaswithproducerinbetween(%S* %src, %S* %dst) {
+; CHECK-LABEL: copyalias
+; CHECK-NEXT: [[LOAD:%[a-z0-9\.]+]] = load %S, %S* %src
+; CHECK-NOT: call
+  %1 = load %S, %S* %src
+  store %S undef, %S* %dst
+  %dst2 = getelementptr %S , %S* %dst, i64 1
+  store %S %1, %S* %dst2
+  ret void
+}




More information about the llvm-commits mailing list