1 ; RUN: opt -data-layout=A5 -S -mtriple=amdgcn-unknown-unknown -passes=amdgpu-promote-alloca -disable-promote-alloca-to-vector < %s | FileCheck -check-prefix=IR %s
2 ; RUN: llc -march=amdgcn -mcpu=fiji -disable-promote-alloca-to-vector < %s | FileCheck -check-prefix=ASM %s
4 ; IR-LABEL: define amdgpu_vs void @promote_alloca_shaders(ptr addrspace(1) inreg %out, ptr addrspace(1) inreg %in) #0 {
7 ; ASM-LABEL: {{^}}promote_alloca_shaders:
8 ; ASM: ; ScratchSize: 24
9 define amdgpu_vs void @promote_alloca_shaders(ptr addrspace(1) inreg %out, ptr addrspace(1) inreg %in) #0 {
11 %stack = alloca [5 x i32], align 4, addrspace(5)
12 %tmp0 = load i32, ptr addrspace(1) %in, align 4
13 %arrayidx1 = getelementptr inbounds [5 x i32], ptr addrspace(5) %stack, i32 0, i32 %tmp0
14 store i32 4, ptr addrspace(5) %arrayidx1, align 4
15 %arrayidx2 = getelementptr inbounds i32, ptr addrspace(1) %in, i32 1
16 %tmp1 = load i32, ptr addrspace(1) %arrayidx2, align 4
17 %arrayidx3 = getelementptr inbounds [5 x i32], ptr addrspace(5) %stack, i32 0, i32 %tmp1
18 store i32 5, ptr addrspace(5) %arrayidx3, align 4
19 %tmp2 = load i32, ptr addrspace(5) %stack, align 4
20 store i32 %tmp2, ptr addrspace(1) %out, align 4
21 %arrayidx5 = getelementptr inbounds [5 x i32], ptr addrspace(5) %stack, i32 0, i32 1
22 %tmp3 = load i32, ptr addrspace(5) %arrayidx5
23 %arrayidx6 = getelementptr inbounds i32, ptr addrspace(1) %out, i32 1
24 store i32 %tmp3, ptr addrspace(1) %arrayidx6
28 ; OPT-LABEL: @promote_to_vector_call_c(
30 ; OPT: extractelement <2 x i32> %{{[0-9]+}}, i32 %in
32 ; ASM-LABEL: {{^}}promote_to_vector_call_c:
33 ; ASM-NOT: LDSByteSize
34 ; ASM: ; ScratchSize: 12
35 define void @promote_to_vector_call_c(ptr addrspace(1) %out, i32 %in) #0 {
37 %tmp = alloca [2 x i32], addrspace(5)
38 %tmp2 = getelementptr [2 x i32], ptr addrspace(5) %tmp, i32 0, i32 1
39 store i32 0, ptr addrspace(5) %tmp
40 store i32 1, ptr addrspace(5) %tmp2
41 %tmp3 = getelementptr [2 x i32], ptr addrspace(5) %tmp, i32 0, i32 %in
42 %tmp4 = load i32, ptr addrspace(5) %tmp3
43 %tmp5 = load volatile i32, ptr addrspace(1) undef
44 %tmp6 = add i32 %tmp4, %tmp5
45 store i32 %tmp6, ptr addrspace(1) %out
49 ; OPT-LABEL: @no_promote_to_lds_c(
52 ; ASM-LABEL: {{^}}no_promote_to_lds_c:
53 ; ASM-NOT: LDSByteSize
54 ; ASM: ; ScratchSize: 24
55 define void @no_promote_to_lds_c(ptr addrspace(1) nocapture %out, ptr addrspace(1) nocapture %in) #0 {
57 %stack = alloca [5 x i32], align 4, addrspace(5)
58 %0 = load i32, ptr addrspace(1) %in, align 4
59 %arrayidx1 = getelementptr inbounds [5 x i32], ptr addrspace(5) %stack, i32 0, i32 %0
60 store i32 4, ptr addrspace(5) %arrayidx1, align 4
61 %arrayidx2 = getelementptr inbounds i32, ptr addrspace(1) %in, i32 1
62 %1 = load i32, ptr addrspace(1) %arrayidx2, align 4
63 %arrayidx3 = getelementptr inbounds [5 x i32], ptr addrspace(5) %stack, i32 0, i32 %1
64 store i32 5, ptr addrspace(5) %arrayidx3, align 4
65 %2 = load i32, ptr addrspace(5) %stack, align 4
66 store i32 %2, ptr addrspace(1) %out, align 4
67 %arrayidx12 = getelementptr inbounds [5 x i32], ptr addrspace(5) %stack, i32 0, i32 1
68 %3 = load i32, ptr addrspace(5) %arrayidx12
69 %arrayidx13 = getelementptr inbounds i32, ptr addrspace(1) %out, i32 1
70 store i32 %3, ptr addrspace(1) %arrayidx13
74 declare i32 @foo(ptr addrspace(5)) #0
76 ; ASM-LABEL: {{^}}call_private:
77 ; ASM: buffer_store_dword
78 ; ASM: buffer_store_dword
80 ; ASM: ScratchSize: 16400
81 define amdgpu_kernel void @call_private(ptr addrspace(1) %out, i32 %in) #0 {
83 %tmp = alloca [2 x i32], addrspace(5)
84 %tmp2 = getelementptr [2 x i32], ptr addrspace(5) %tmp, i32 0, i32 1
85 store i32 0, ptr addrspace(5) %tmp
86 store i32 1, ptr addrspace(5) %tmp2
87 %tmp3 = getelementptr [2 x i32], ptr addrspace(5) %tmp, i32 0, i32 %in
88 %val = call i32 @foo(ptr addrspace(5) %tmp3)
89 store i32 %val, ptr addrspace(1) %out
93 declare i32 @llvm.amdgcn.workitem.id.x() #1
95 attributes #0 = { nounwind "amdgpu-flat-work-group-size"="64,64" }
96 attributes #1 = { nounwind readnone }