1; RUN: llc -O0 -march=amdgcn -mtriple=amdgcn-unknown-amdhsa -mcpu=kaveri --amdhsa-code-object-version=2 -mattr=+promote-alloca < %s | FileCheck -check-prefix=NOOPTS -check-prefix=ALL %s
2; RUN: llc -O1 -march=amdgcn -mtriple=amdgcn-unknown-amdhsa -mcpu=kaveri --amdhsa-code-object-version=2 -mattr=+promote-alloca < %s | FileCheck -check-prefix=OPTS -check-prefix=ALL %s
3
4; ALL-LABEL: {{^}}promote_alloca_i32_array_array:
5; NOOPTS: workgroup_group_segment_byte_size = 0{{$}}
6; NOOPTS-NOT: ds_write
7; OPTS: ds_write
8define amdgpu_kernel void @promote_alloca_i32_array_array(i32 addrspace(1)* %out, i32 %index) #0 {
9entry:
10  %alloca = alloca [2 x [2 x i32]], addrspace(5)
11  %gep0 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]] addrspace(5)* %alloca, i32 0, i32 0, i32 0
12  %gep1 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]] addrspace(5)* %alloca, i32 0, i32 0, i32 1
13  store i32 0, i32 addrspace(5)* %gep0
14  store i32 1, i32 addrspace(5)* %gep1
15  %gep2 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]] addrspace(5)* %alloca, i32 0, i32 0, i32 %index
16  %load = load i32, i32 addrspace(5)* %gep2
17  store i32 %load, i32 addrspace(1)* %out
18  ret void
19}
20
21; ALL-LABEL: {{^}}optnone_promote_alloca_i32_array_array:
22; ALL: workgroup_group_segment_byte_size = 0{{$}}
23; ALL-NOT: ds_write
24define amdgpu_kernel void @optnone_promote_alloca_i32_array_array(i32 addrspace(1)* %out, i32 %index) #1 {
25entry:
26  %alloca = alloca [2 x [2 x i32]], addrspace(5)
27  %gep0 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]] addrspace(5)* %alloca, i32 0, i32 0, i32 0
28  %gep1 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]] addrspace(5)* %alloca, i32 0, i32 0, i32 1
29  store i32 0, i32 addrspace(5)* %gep0
30  store i32 1, i32 addrspace(5)* %gep1
31  %gep2 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]] addrspace(5)* %alloca, i32 0, i32 0, i32 %index
32  %load = load i32, i32 addrspace(5)* %gep2
33  store i32 %load, i32 addrspace(1)* %out
34  ret void
35}
36
37attributes #0 = { nounwind "amdgpu-flat-work-group-size"="64,64" }
38attributes #1 = { nounwind optnone noinline "amdgpu-flat-work-group-size"="64,64" }
39