1 ; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -mcpu=kaveri -amdgpu-promote-alloca < %s | FileCheck %s
3 declare void @llvm.memcpy.p0i8.p1i8.i32(i8* nocapture, i8 addrspace(1)* nocapture, i32, i1) #0
4 declare void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* nocapture, i8* nocapture, i32, i1) #0
5 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) #0
7 declare void @llvm.memmove.p0i8.p1i8.i32(i8* nocapture, i8 addrspace(1)* nocapture, i32, i1) #0
8 declare void @llvm.memmove.p1i8.p0i8.i32(i8 addrspace(1)* nocapture, i8* nocapture, i32, i1) #0
9 declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) #0
11 declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i1) #0
13 declare i32 @llvm.objectsize.i32.p0i8(i8*, i1, i1, i1) #1
15 ; CHECK-LABEL: @promote_with_memcpy(
16 ; CHECK: getelementptr inbounds [64 x [17 x i32]], [64 x [17 x i32]] addrspace(3)* @promote_with_memcpy.alloca, i32 0, i32 %{{[0-9]+}}
17 ; CHECK: call void @llvm.memcpy.p3i8.p1i8.i32(i8 addrspace(3)* align 4 %alloca.bc, i8 addrspace(1)* align 4 %in.bc, i32 68, i1 false)
18 ; CHECK: call void @llvm.memcpy.p1i8.p3i8.i32(i8 addrspace(1)* align 4 %out.bc, i8 addrspace(3)* align 4 %alloca.bc, i32 68, i1 false)
19 define amdgpu_kernel void @promote_with_memcpy(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
20 %alloca = alloca [17 x i32], align 4
21 %alloca.bc = bitcast [17 x i32]* %alloca to i8*
22 %in.bc = bitcast i32 addrspace(1)* %in to i8 addrspace(1)*
23 %out.bc = bitcast i32 addrspace(1)* %out to i8 addrspace(1)*
24 call void @llvm.memcpy.p0i8.p1i8.i32(i8* align 4 %alloca.bc, i8 addrspace(1)* align 4 %in.bc, i32 68, i1 false)
25 call void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* align 4 %out.bc, i8* align 4 %alloca.bc, i32 68, i1 false)
29 ; CHECK-LABEL: @promote_with_memmove(
30 ; CHECK: getelementptr inbounds [64 x [17 x i32]], [64 x [17 x i32]] addrspace(3)* @promote_with_memmove.alloca, i32 0, i32 %{{[0-9]+}}
31 ; CHECK: call void @llvm.memmove.p3i8.p1i8.i32(i8 addrspace(3)* align 4 %alloca.bc, i8 addrspace(1)* align 4 %in.bc, i32 68, i1 false)
32 ; CHECK: call void @llvm.memmove.p1i8.p3i8.i32(i8 addrspace(1)* align 4 %out.bc, i8 addrspace(3)* align 4 %alloca.bc, i32 68, i1 false)
33 define amdgpu_kernel void @promote_with_memmove(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
34 %alloca = alloca [17 x i32], align 4
35 %alloca.bc = bitcast [17 x i32]* %alloca to i8*
36 %in.bc = bitcast i32 addrspace(1)* %in to i8 addrspace(1)*
37 %out.bc = bitcast i32 addrspace(1)* %out to i8 addrspace(1)*
38 call void @llvm.memmove.p0i8.p1i8.i32(i8* align 4 %alloca.bc, i8 addrspace(1)* align 4 %in.bc, i32 68, i1 false)
39 call void @llvm.memmove.p1i8.p0i8.i32(i8 addrspace(1)* align 4 %out.bc, i8* align 4 %alloca.bc, i32 68, i1 false)
43 ; CHECK-LABEL: @promote_with_memset(
44 ; CHECK: getelementptr inbounds [64 x [17 x i32]], [64 x [17 x i32]] addrspace(3)* @promote_with_memset.alloca, i32 0, i32 %{{[0-9]+}}
45 ; CHECK: call void @llvm.memset.p3i8.i32(i8 addrspace(3)* align 4 %alloca.bc, i8 7, i32 68, i1 false)
46 define amdgpu_kernel void @promote_with_memset(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
47 %alloca = alloca [17 x i32], align 4
48 %alloca.bc = bitcast [17 x i32]* %alloca to i8*
49 %in.bc = bitcast i32 addrspace(1)* %in to i8 addrspace(1)*
50 %out.bc = bitcast i32 addrspace(1)* %out to i8 addrspace(1)*
51 call void @llvm.memset.p0i8.i32(i8* align 4 %alloca.bc, i8 7, i32 68, i1 false)
55 ; CHECK-LABEL: @promote_with_objectsize(
56 ; CHECK: [[PTR:%[0-9]+]] = getelementptr inbounds [64 x [17 x i32]], [64 x [17 x i32]] addrspace(3)* @promote_with_objectsize.alloca, i32 0, i32 %{{[0-9]+}}
57 ; CHECK: call i32 @llvm.objectsize.i32.p3i8(i8 addrspace(3)* %alloca.bc, i1 false, i1 false, i1 false)
58 define amdgpu_kernel void @promote_with_objectsize(i32 addrspace(1)* %out) #0 {
59 %alloca = alloca [17 x i32], align 4
60 %alloca.bc = bitcast [17 x i32]* %alloca to i8*
61 %size = call i32 @llvm.objectsize.i32.p0i8(i8* %alloca.bc, i1 false, i1 false, i1 false)
62 store i32 %size, i32 addrspace(1)* %out
66 ; CHECK-LABEL: @promote_alloca_used_twice_in_memcpy(
67 ; CHECK: %i = bitcast double addrspace(3)* %arrayidx1 to i8 addrspace(3)*
68 ; CHECK: %i1 = bitcast double addrspace(3)* %arrayidx2 to i8 addrspace(3)*
69 ; CHECK: call void @llvm.memcpy.p3i8.p3i8.i64(i8 addrspace(3)* align 8 dereferenceable(16) %i, i8 addrspace(3)* align 8 dereferenceable(16) %i1, i64 16, i1 false)
70 define amdgpu_kernel void @promote_alloca_used_twice_in_memcpy(i32 %c) {
72 %r = alloca double, align 8
73 %arrayidx1 = getelementptr inbounds double, double* %r, i32 1
74 %i = bitcast double* %arrayidx1 to i8*
75 %arrayidx2 = getelementptr inbounds double, double* %r, i32 %c
76 %i1 = bitcast double* %arrayidx2 to i8*
77 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 dereferenceable(16) %i, i8* align 8 dereferenceable(16) %i1, i64 16, i1 false)
81 ; CHECK-LABEL: @promote_alloca_used_twice_in_memmove(
82 ; CHECK: %i = bitcast double addrspace(3)* %arrayidx1 to i8 addrspace(3)*
83 ; CHECK: %i1 = bitcast double addrspace(3)* %arrayidx2 to i8 addrspace(3)*
84 ; CHECK: call void @llvm.memmove.p3i8.p3i8.i64(i8 addrspace(3)* align 8 dereferenceable(16) %i, i8 addrspace(3)* align 8 dereferenceable(16) %i1, i64 16, i1 false)
85 define amdgpu_kernel void @promote_alloca_used_twice_in_memmove(i32 %c) {
87 %r = alloca double, align 8
88 %arrayidx1 = getelementptr inbounds double, double* %r, i32 1
89 %i = bitcast double* %arrayidx1 to i8*
90 %arrayidx2 = getelementptr inbounds double, double* %r, i32 %c
91 %i1 = bitcast double* %arrayidx2 to i8*
92 call void @llvm.memmove.p0i8.p0i8.i64(i8* align 8 dereferenceable(16) %i, i8* align 8 dereferenceable(16) %i1, i64 16, i1 false)
96 attributes #0 = { nounwind "amdgpu-flat-work-group-size"="64,64" "amdgpu-waves-per-eu"="1,3" }
97 attributes #1 = { nounwind readnone }