[PATCH] D16789: AMDGPU: Handle promoting memmove
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 1 16:33:14 PST 2016
arsenm created this revision.
arsenm added a reviewer: tstellarAMD.
arsenm added a subscriber: llvm-commits.
Herald added a subscriber: arsenm.
Also add missing tests for the others.
http://reviews.llvm.org/D16789
Files:
lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
test/CodeGen/AMDGPU/promote-alloca-mem-intrinsics.ll
Index: test/CodeGen/AMDGPU/promote-alloca-mem-intrinsics.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AMDGPU/promote-alloca-mem-intrinsics.ll
@@ -0,0 +1,52 @@
+; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-promote-alloca < %s | FileCheck %s
+
+declare void @llvm.memcpy.p0i8.p1i8.i32(i8* nocapture, i8 addrspace(1)* nocapture, i32, i32, i1) #0
+declare void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* nocapture, i8* nocapture, i32, i32, i1) #0
+
+declare void @llvm.memmove.p0i8.p1i8.i32(i8* nocapture, i8 addrspace(1)* nocapture, i32, i32, i1) #0
+declare void @llvm.memmove.p1i8.p0i8.i32(i8 addrspace(1)* nocapture, i8* nocapture, i32, i32, i1) #0
+
+declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) #0
+
+
+; CHECK-LABEL: @promote_with_memcpy(
+; CHECK: getelementptr inbounds [256 x [17 x i32]], [256 x [17 x i32]] addrspace(3)* @alloca, i32 0, i32 %{{[0-9]+}}
+; CHECK: call void @llvm.memcpy.p3i8.p1i8.i32(i8 addrspace(3)* %alloca.bc, i8 addrspace(1)* %in.bc, i32 68, i32 4, i1 false)
+; CHECK: call void @llvm.memcpy.p1i8.p3i8.i32(i8 addrspace(1)* %out.bc, i8 addrspace(3)* %alloca.bc, i32 68, i32 4, i1 false)
+define void @promote_with_memcpy(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
+ %alloca = alloca [17 x i32], align 16
+ %alloca.bc = bitcast [17 x i32]* %alloca to i8*
+ %in.bc = bitcast i32 addrspace(1)* %in to i8 addrspace(1)*
+ %out.bc = bitcast i32 addrspace(1)* %out to i8 addrspace(1)*
+ call void @llvm.memcpy.p0i8.p1i8.i32(i8* %alloca.bc, i8 addrspace(1)* %in.bc, i32 68, i32 4, i1 false)
+ call void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* %out.bc, i8* %alloca.bc, i32 68, i32 4, i1 false)
+ ret void
+}
+
+; CHECK-LABEL: @promote_with_memmove(
+; CHECK: getelementptr inbounds [256 x [17 x i32]], [256 x [17 x i32]] addrspace(3)* @alloca.1, i32 0, i32 %{{[0-9]+}}
+; CHECK: call void @llvm.memmove.p3i8.p1i8.i32(i8 addrspace(3)* %alloca.bc, i8 addrspace(1)* %in.bc, i32 68, i32 4, i1 false)
+; CHECK: call void @llvm.memmove.p1i8.p3i8.i32(i8 addrspace(1)* %out.bc, i8 addrspace(3)* %alloca.bc, i32 68, i32 4, i1 false)
+define void @promote_with_memmove(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
+ %alloca = alloca [17 x i32], align 16
+ %alloca.bc = bitcast [17 x i32]* %alloca to i8*
+ %in.bc = bitcast i32 addrspace(1)* %in to i8 addrspace(1)*
+ %out.bc = bitcast i32 addrspace(1)* %out to i8 addrspace(1)*
+ call void @llvm.memmove.p0i8.p1i8.i32(i8* %alloca.bc, i8 addrspace(1)* %in.bc, i32 68, i32 4, i1 false)
+ call void @llvm.memmove.p1i8.p0i8.i32(i8 addrspace(1)* %out.bc, i8* %alloca.bc, i32 68, i32 4, i1 false)
+ ret void
+}
+
+; CHECK-LABEL: @promote_with_memset(
+; CHECK: getelementptr inbounds [256 x [17 x i32]], [256 x [17 x i32]] addrspace(3)* @alloca.2, i32 0, i32 %{{[0-9]+}}
+; CHECK: call void @llvm.memset.p3i8.i32(i8 addrspace(3)* %alloca.bc, i8 7, i32 68, i32 4, i1 false)
+define void @promote_with_memset(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
+ %alloca = alloca [17 x i32], align 16
+ %alloca.bc = bitcast [17 x i32]* %alloca to i8*
+ %in.bc = bitcast i32 addrspace(1)* %in to i8 addrspace(1)*
+ %out.bc = bitcast i32 addrspace(1)* %out to i8 addrspace(1)*
+ call void @llvm.memset.p0i8.i32(i8* %alloca.bc, i8 7, i32 68, i32 4, i1 false)
+ ret void
+}
+
+attributes #0 = { nounwind }
Index: lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
===================================================================
--- lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -406,6 +406,7 @@
switch (II->getIntrinsicID()) {
case Intrinsic::memcpy:
+ case Intrinsic::memmove:
case Intrinsic::memset:
case Intrinsic::lifetime_start:
case Intrinsic::lifetime_end:
@@ -579,6 +580,14 @@
Intr->eraseFromParent();
continue;
}
+ case Intrinsic::memmove: {
+ MemMoveInst *MemMove = cast<MemMoveInst>(Intr);
+ Builder.CreateMemMove(MemMove->getRawDest(), MemMove->getRawSource(),
+ MemMove->getLength(), MemMove->getAlignment(),
+ MemMove->isVolatile());
+ Intr->eraseFromParent();
+ continue;
+ }
case Intrinsic::memset: {
MemSetInst *MemSet = cast<MemSetInst>(Intr);
Builder.CreateMemSet(MemSet->getRawDest(), MemSet->getValue(),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16789.46592.patch
Type: text/x-patch
Size: 4373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160202/18787a2e/attachment.bin>
More information about the llvm-commits
mailing list