]> granicus.if.org Git - llvm/commitdiff
Merging r299866:
authorTom Stellard <tstellar@redhat.com>
Tue, 23 May 2017 17:13:15 +0000 (17:13 +0000)
committerTom Stellard <tstellar@redhat.com>
Tue, 23 May 2017 17:13:15 +0000 (17:13 +0000)
------------------------------------------------------------------------
r299866 | arsenm | 2017-04-10 15:00:25 -0400 (Mon, 10 Apr 2017) | 3 lines

[MemCpyOpt] Only replace memcpy with bitcast if address spaces match

Patch by James Price
------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_40@303657 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/MemCpyOptimizer.cpp
test/Transforms/MemCpyOpt/memcpy.ll

index 1b590140f70aaea61391ae0b9e3c15fcd9cdc723..8355f952e317f953eea04a0ae69986cac074c67c 100644 (file)
@@ -1306,6 +1306,11 @@ bool MemCpyOptPass::processByValArgument(CallSite CS, unsigned ArgNo) {
                                  CS.getInstruction(), &AC, &DT) < ByValAlign)
     return false;
 
+  // The address space of the memcpy source must match the byval argument
+  if (MDep->getSource()->getType()->getPointerAddressSpace() !=
+      ByValArg->getType()->getPointerAddressSpace())
+    return false;
+
   // Verify that the copied-from memory doesn't change in between the memcpy and
   // the byval call.
   //    memcpy(a <- b)
index 6181543cfc63a7c2b6b121638ebe86e5942adda4..01ed78d4add1602884cd6795a08b7abdbc640cd4 100644 (file)
@@ -76,8 +76,21 @@ define void @test4(i8 *%P) {
 ; CHECK-NEXT: call void @test4a(
 }
 
+; Make sure we don't remove the memcpy if the source address space doesn't match the byval argument
+define void @test4_addrspace(i8 addrspace(1)* %P) {
+  %A = alloca %1
+  %a = bitcast %1* %A to i8*
+  call void @llvm.memcpy.p0i8.p1i8.i64(i8* %a, i8 addrspace(1)* %P, i64 8, i32 4, i1 false)
+  call void @test4a(i8* align 1 byval %a)
+  ret void
+; CHECK-LABEL: @test4_addrspace(
+; CHECK: call void @llvm.memcpy.p0i8.p1i8.i64(
+; CHECK-NEXT: call void @test4a(
+}
+
 declare void @test4a(i8* align 1 byval)
 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+declare void @llvm.memcpy.p0i8.p1i8.i64(i8* nocapture, i8 addrspace(1)* nocapture, i64, i32, i1) nounwind
 declare void @llvm.memcpy.p1i8.p1i8.i64(i8 addrspace(1)* nocapture, i8 addrspace(1)* nocapture, i64, i32, i1) nounwind
 
 %struct.S = type { i128, [4 x i8]}