From: Fiona Glaser Date: Tue, 14 Mar 2017 22:37:38 +0000 (+0000) Subject: MemCpyOptimizer: don't create new addrspace casts X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=54dc1ed08891355662d5c17b72628395e62e2c42;p=llvm MemCpyOptimizer: don't create new addrspace casts This isn't safe on all targets, and since we don't have a way to know it's safe, avoid doing it for now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297788 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp index c5e69cd0f99..f161d6710ab 100644 --- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -932,6 +932,17 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpy, Value *cpyDest, if (MR != MRI_NoModRef) return false; + // We can't create address space casts here because we don't know if they're + // safe for the target. + if (cpySrc->getType()->getPointerAddressSpace() != + cpyDest->getType()->getPointerAddressSpace()) + return false; + for (unsigned i = 0; i < CS.arg_size(); ++i) + if (CS.getArgument(i)->stripPointerCasts() == cpySrc && + cpySrc->getType()->getPointerAddressSpace() != + CS.getArgument(i)->getType()->getPointerAddressSpace()) + return false; + // All the checks have passed, so do the transformation. bool changedArgument = false; for (unsigned i = 0; i < CS.arg_size(); ++i) diff --git a/test/Transforms/MemCpyOpt/memcpy.ll b/test/Transforms/MemCpyOpt/memcpy.ll index 6181543cfc6..f638d8d5701 100644 --- a/test/Transforms/MemCpyOpt/memcpy.ll +++ b/test/Transforms/MemCpyOpt/memcpy.ll @@ -202,6 +202,21 @@ define void @test10(%opaque* noalias nocapture sret %x, i32 %y) { ret void } +; don't create new addressspacecasts when we don't know they're safe for the target +define void @test11([20 x i32] addrspace(1)* nocapture dereferenceable(80) %P) { + %A = alloca [20 x i32], align 4 + %a = bitcast [20 x i32]* %A to i8* + %b = bitcast [20 x i32] addrspace(1)* %P to i8 addrspace(1)* + call void @llvm.memset.p0i8.i64(i8* %a, i8 0, i64 80, i32 4, i1 false) + call void @llvm.memcpy.p1i8.p0i8.i64(i8 addrspace(1)* %b, i8* %a, i64 80, i32 4, i1 false) + ret void +; CHECK-LABEL: @test11( +; CHECK-NOT: addrspacecast +} + +declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind +declare void @llvm.memcpy.p1i8.p0i8.i64(i8 addrspace(1)* nocapture, i8* nocapture, i64, i32, i1) nounwind + declare void @f1(%struct.big* nocapture sret) declare void @f2(%struct.big*)