Skip to content

Commit eba2561

Browse files
committed
Merging r299866:
------------------------------------------------------------------------ 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
1 parent f34c300 commit eba2561

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Transforms/Scalar/MemCpyOptimizer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,11 @@ bool MemCpyOptPass::processByValArgument(CallSite CS, unsigned ArgNo) {
13061306
CS.getInstruction(), &AC, &DT) < ByValAlign)
13071307
return false;
13081308

1309+
// The address space of the memcpy source must match the byval argument
1310+
if (MDep->getSource()->getType()->getPointerAddressSpace() !=
1311+
ByValArg->getType()->getPointerAddressSpace())
1312+
return false;
1313+
13091314
// Verify that the copied-from memory doesn't change in between the memcpy and
13101315
// the byval call.
13111316
// memcpy(a <- b)

test/Transforms/MemCpyOpt/memcpy.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,21 @@ define void @test4(i8 *%P) {
7676
; CHECK-NEXT: call void @test4a(
7777
}
7878

79+
; Make sure we don't remove the memcpy if the source address space doesn't match the byval argument
80+
define void @test4_addrspace(i8 addrspace(1)* %P) {
81+
%A = alloca %1
82+
%a = bitcast %1* %A to i8*
83+
call void @llvm.memcpy.p0i8.p1i8.i64(i8* %a, i8 addrspace(1)* %P, i64 8, i32 4, i1 false)
84+
call void @test4a(i8* align 1 byval %a)
85+
ret void
86+
; CHECK-LABEL: @test4_addrspace(
87+
; CHECK: call void @llvm.memcpy.p0i8.p1i8.i64(
88+
; CHECK-NEXT: call void @test4a(
89+
}
90+
7991
declare void @test4a(i8* align 1 byval)
8092
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
93+
declare void @llvm.memcpy.p0i8.p1i8.i64(i8* nocapture, i8 addrspace(1)* nocapture, i64, i32, i1) nounwind
8194
declare void @llvm.memcpy.p1i8.p1i8.i64(i8 addrspace(1)* nocapture, i8 addrspace(1)* nocapture, i64, i32, i1) nounwind
8295

8396
%struct.S = type { i128, [4 x i8]}

0 commit comments

Comments
 (0)