1 ; RUN: llc -march=amdgcn -disable-promote-alloca-to-vector -verify-machineinstrs < %s | FileCheck %s
3 declare i8 addrspace(4)* @llvm.amdgcn.kernarg.segment.ptr() #1
5 declare i32 @llvm.amdgcn.workitem.id.x() #1
8 declare void @llvm.amdgcn.s.dcache.inv.vol() #0
11 declare void @llvm.amdgcn.s.dcache.wb() #0
13 ; CHECK-LABEL: {{^}}target_none:
14 ; CHECK: s_movk_i32 [[OFFSETREG:s[0-9]+]], 0x400
15 ; CHECK: s_load_dwordx2 s{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, [[OFFSETREG]]
16 ; CHECK: buffer_store_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64
17 define amdgpu_kernel void @target_none() #0 {
18 %kernargs = call i8 addrspace(4)* @llvm.amdgcn.kernarg.segment.ptr()
19 %kernargs.gep = getelementptr inbounds i8, i8 addrspace(4)* %kernargs, i64 1024
20 %kernargs.gep.cast = bitcast i8 addrspace(4)* %kernargs.gep to i32 addrspace(1)* addrspace(4)*
21 %ptr = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(4)* %kernargs.gep.cast
22 %id = call i32 @llvm.amdgcn.workitem.id.x()
23 %id.ext = sext i32 %id to i64
24 %gep = getelementptr inbounds i32, i32 addrspace(1)* %ptr, i64 %id.ext
25 store i32 0, i32 addrspace(1)* %gep
29 ; CHECK-LABEL: {{^}}target_tahiti:
30 ; CHECK: s_movk_i32 [[OFFSETREG:s[0-9]+]], 0x400
31 ; CHECK: s_load_dwordx2 s{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, [[OFFSETREG]]
32 ; CHECK: buffer_store_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64
33 define amdgpu_kernel void @target_tahiti() #1 {
34 %kernargs = call i8 addrspace(4)* @llvm.amdgcn.kernarg.segment.ptr()
35 %kernargs.gep = getelementptr inbounds i8, i8 addrspace(4)* %kernargs, i64 1024
36 %kernargs.gep.cast = bitcast i8 addrspace(4)* %kernargs.gep to i32 addrspace(1)* addrspace(4)*
37 %ptr = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(4)* %kernargs.gep.cast
38 %id = call i32 @llvm.amdgcn.workitem.id.x()
39 %id.ext = sext i32 %id to i64
40 %gep = getelementptr inbounds i32, i32 addrspace(1)* %ptr, i64 %id.ext
41 store i32 0, i32 addrspace(1)* %gep
45 ; CHECK-LABEL: {{^}}target_bonaire:
46 ; CHECK: s_load_dwordx2 s{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0x100
47 ; CHECK: buffer_store_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64
48 ; CHECK: s_dcache_inv_vol
49 define amdgpu_kernel void @target_bonaire() #3 {
50 %kernargs = call i8 addrspace(4)* @llvm.amdgcn.kernarg.segment.ptr()
51 %kernargs.gep = getelementptr inbounds i8, i8 addrspace(4)* %kernargs, i64 1024
52 %kernargs.gep.cast = bitcast i8 addrspace(4)* %kernargs.gep to i32 addrspace(1)* addrspace(4)*
53 %ptr = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(4)* %kernargs.gep.cast
54 %id = call i32 @llvm.amdgcn.workitem.id.x()
55 %id.ext = sext i32 %id to i64
56 %gep = getelementptr inbounds i32, i32 addrspace(1)* %ptr, i64 %id.ext
57 store i32 0, i32 addrspace(1)* %gep
58 call void @llvm.amdgcn.s.dcache.inv.vol()
62 ; CHECK-LABEL: {{^}}target_fiji:
63 ; CHECK: s_load_dwordx2 s{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0x400
64 ; CHECK: flat_store_dword
65 ; CHECK: s_dcache_wb{{$}}
66 define amdgpu_kernel void @target_fiji() #4 {
67 %kernargs = call i8 addrspace(4)* @llvm.amdgcn.kernarg.segment.ptr()
68 %kernargs.gep = getelementptr inbounds i8, i8 addrspace(4)* %kernargs, i64 1024
69 %kernargs.gep.cast = bitcast i8 addrspace(4)* %kernargs.gep to i32 addrspace(1)* addrspace(4)*
70 %ptr = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(4)* %kernargs.gep.cast
71 %id = call i32 @llvm.amdgcn.workitem.id.x()
72 %id.ext = sext i32 %id to i64
73 %gep = getelementptr inbounds i32, i32 addrspace(1)* %ptr, i64 %id.ext
74 store i32 0, i32 addrspace(1)* %gep
75 call void @llvm.amdgcn.s.dcache.wb()
79 ; CHECK-LABEL: {{^}}promote_alloca_enabled:
81 define amdgpu_kernel void @promote_alloca_enabled(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) #5 {
83 %stack = alloca [5 x i32], align 4, addrspace(5)
84 %tmp = load i32, i32 addrspace(1)* %in, align 4
85 %arrayidx1 = getelementptr inbounds [5 x i32], [5 x i32] addrspace(5)* %stack, i32 0, i32 %tmp
86 %load = load i32, i32 addrspace(5)* %arrayidx1
87 store i32 %load, i32 addrspace(1)* %out
91 ; CHECK-LABEL: {{^}}promote_alloca_disabled:
92 ; CHECK: SCRATCH_RSRC_DWORD0
93 ; CHECK: SCRATCH_RSRC_DWORD1
94 ; CHECK: ScratchSize: 24
95 define amdgpu_kernel void @promote_alloca_disabled(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) #6 {
97 %stack = alloca [5 x i32], align 4, addrspace(5)
98 %tmp = load i32, i32 addrspace(1)* %in, align 4
99 %arrayidx1 = getelementptr inbounds [5 x i32], [5 x i32] addrspace(5)* %stack, i32 0, i32 %tmp
100 %load = load i32, i32 addrspace(5)* %arrayidx1
101 store i32 %load, i32 addrspace(1)* %out
105 attributes #0 = { nounwind }
106 attributes #1 = { nounwind readnone }
107 attributes #2 = { nounwind "target-cpu"="tahiti" }
108 attributes #3 = { nounwind "target-cpu"="bonaire" }
109 attributes #4 = { nounwind "target-cpu"="fiji" }
110 attributes #5 = { nounwind "target-features"="+promote-alloca" "amdgpu-waves-per-eu"="1,3" }
111 attributes #6 = { nounwind "target-features"="-promote-alloca" "amdgpu-waves-per-eu"="1,3" }