1 ; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown -mcpu=bonaire < %s | FileCheck -check-prefix=OPT -check-prefix=OPT-CI -check-prefix=OPT-CIVI %s
2 ; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown -mcpu=tonga -mattr=-flat-for-global < %s | FileCheck -check-prefix=OPT -check-prefix=OPT-VI -check-prefix=OPT-CIVI %s
3 ; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown -mcpu=gfx900 -mattr=-flat-for-global < %s | FileCheck -check-prefix=OPT -check-prefix=OPT-GFX9 %s
4 ; RUN: llc -march=amdgcn -amdgpu-scalarize-global-loads=false -mcpu=bonaire -mattr=-promote-alloca < %s | FileCheck -check-prefix=GCN -check-prefix=CI -check-prefix=CIVI %s
5 ; RUN: llc -march=amdgcn -amdgpu-scalarize-global-loads=false -mcpu=tonga -mattr=-flat-for-global -mattr=-promote-alloca < %s | FileCheck -check-prefix=GCN -check-prefix=VI -check-prefix=CIVI %s
6 ; RUN: llc -march=amdgcn -amdgpu-scalarize-global-loads=false -mcpu=gfx900 -mattr=-flat-for-global -mattr=-promote-alloca < %s | FileCheck -check-prefix=GCN -check-prefix=GFX9 %s
8 ; OPT-LABEL: @test_no_sink_flat_small_offset_i32(
9 ; OPT-CIVI: getelementptr i32, i32* %in
11 ; OPT-CIVI-NOT: ptrtoint
14 ; OPT-GFX9: %sunkaddr = getelementptr i8, i8* %0, i64 28
15 ; OPT-GFX9: %1 = bitcast i8* %sunkaddr to i32*
16 ; OPT-GFX9: load i32, i32* %1
18 ; GCN-LABEL: {{^}}test_no_sink_flat_small_offset_i32:
19 ; GCN: flat_load_dword
21 define amdgpu_kernel void @test_no_sink_flat_small_offset_i32(i32* %out, i32* %in, i32 %cond) {
23 %out.gep = getelementptr i32, i32* %out, i64 999999
24 %in.gep = getelementptr i32, i32* %in, i64 7
25 %tmp0 = icmp eq i32 %cond, 0
26 br i1 %tmp0, label %endif, label %if
29 %tmp1 = load i32, i32* %in.gep
33 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
34 store i32 %x, i32* %out.gep
41 ; OPT-LABEL: @test_sink_noop_addrspacecast_flat_to_global_i32(
42 ; OPT: getelementptr i32, i32* %out,
43 ; rOPT-CI-NOT: getelementptr
46 ; OPT-CI: addrspacecast
47 ; OPT-CI: getelementptr
51 ; GCN-LABEL: {{^}}test_sink_noop_addrspacecast_flat_to_global_i32:
52 ; CI: buffer_load_dword {{v[0-9]+}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:28
53 define amdgpu_kernel void @test_sink_noop_addrspacecast_flat_to_global_i32(i32* %out, i32* %in, i32 %cond) {
55 %out.gep = getelementptr i32, i32* %out, i64 999999
56 %in.gep = getelementptr i32, i32* %in, i64 7
57 %cast = addrspacecast i32* %in.gep to i32 addrspace(1)*
58 %tmp0 = icmp eq i32 %cond, 0
59 br i1 %tmp0, label %endif, label %if
62 %tmp1 = load i32, i32 addrspace(1)* %cast
66 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
67 store i32 %x, i32* %out.gep
74 ; OPT-LABEL: @test_sink_noop_addrspacecast_flat_to_constant_i32(
75 ; OPT: getelementptr i32, i32* %out,
76 ; OPT-CI-NOT: getelementptr
79 ; OPT-CI: addrspacecast
80 ; OPT-CI: getelementptr
84 ; GCN-LABEL: {{^}}test_sink_noop_addrspacecast_flat_to_constant_i32:
85 ; CI: s_load_dword {{s[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}}, 0xd
86 define amdgpu_kernel void @test_sink_noop_addrspacecast_flat_to_constant_i32(i32* %out, i32* %in, i32 %cond) {
88 %out.gep = getelementptr i32, i32* %out, i64 999999
89 %in.gep = getelementptr i32, i32* %in, i64 7
90 %cast = addrspacecast i32* %in.gep to i32 addrspace(4)*
91 %tmp0 = icmp eq i32 %cond, 0
92 br i1 %tmp0, label %endif, label %if
95 %tmp1 = load i32, i32 addrspace(4)* %cast
99 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
100 store i32 %x, i32* %out.gep
107 ; OPT-LABEL: @test_sink_flat_small_max_flat_offset(
108 ; OPT-CIVI: %in.gep = getelementptr i8, i8* %in, i64 4095
110 ; OPT-CIVI-NOT: getelementptr
111 ; OPT-CIVI: load i8, i8* %in.gep
114 ; OPT-GFX9: %sunkaddr = getelementptr i8, i8* %in, i64 4095
115 ; OPT-GFX9: load i8, i8* %sunkaddr
117 ; GCN-LABEL: {{^}}test_sink_flat_small_max_flat_offset:
118 ; GFX9: flat_load_sbyte v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}} offset:4095{{$}}
119 ; CIVI: flat_load_sbyte v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]$}}
120 define amdgpu_kernel void @test_sink_flat_small_max_flat_offset(i32* %out, i8* %in) #1 {
122 %out.gep = getelementptr i32, i32* %out, i32 1024
123 %in.gep = getelementptr i8, i8* %in, i64 4095
124 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
125 %tmp0 = icmp eq i32 %tid, 0
126 br i1 %tmp0, label %endif, label %if
129 %tmp1 = load i8, i8* %in.gep
130 %tmp2 = sext i8 %tmp1 to i32
134 %x = phi i32 [ %tmp2, %if ], [ 0, %entry ]
135 store i32 %x, i32* %out.gep
142 ; OPT-LABEL: @test_sink_flat_small_max_plus_1_flat_offset(
143 ; OPT: %in.gep = getelementptr i8, i8* %in, i64 4096
145 ; OPT-NOT: getelementptr
146 ; OPT: load i8, i8* %in.gep
148 ; GCN-LABEL: {{^}}test_sink_flat_small_max_plus_1_flat_offset:
149 ; GCN: flat_load_sbyte v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]$}}
150 define amdgpu_kernel void @test_sink_flat_small_max_plus_1_flat_offset(i32* %out, i8* %in) #1 {
152 %out.gep = getelementptr i32, i32* %out, i64 99999
153 %in.gep = getelementptr i8, i8* %in, i64 4096
154 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
155 %tmp0 = icmp eq i32 %tid, 0
156 br i1 %tmp0, label %endif, label %if
159 %tmp1 = load i8, i8* %in.gep
160 %tmp2 = sext i8 %tmp1 to i32
164 %x = phi i32 [ %tmp2, %if ], [ 0, %entry ]
165 store i32 %x, i32* %out.gep
172 ; OPT-LABEL: @test_no_sink_flat_reg_offset(
173 ; OPT: %in.gep = getelementptr i8, i8* %in, i64 %reg
176 ; OPT-NOT: getelementptr
177 ; OPT: load i8, i8* %in.gep
179 ; GCN-LABEL: {{^}}test_no_sink_flat_reg_offset:
180 ; GCN: flat_load_sbyte v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]$}}
181 define amdgpu_kernel void @test_no_sink_flat_reg_offset(i32* %out, i8* %in, i64 %reg) #1 {
183 %out.gep = getelementptr i32, i32* %out, i32 1024
184 %in.gep = getelementptr i8, i8* %in, i64 %reg
185 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
186 %tmp0 = icmp eq i32 %tid, 0
187 br i1 %tmp0, label %endif, label %if
190 %tmp1 = load i8, i8* %in.gep
191 %tmp2 = sext i8 %tmp1 to i32
195 %x = phi i32 [ %tmp2, %if ], [ 0, %entry ]
196 store i32 %x, i32* %out.gep
203 declare i32 @llvm.amdgcn.mbcnt.lo(i32, i32) #0
205 attributes #0 = { nounwind readnone }
206 attributes #1 = { nounwind }
207 attributes #2 = { nounwind argmemonly }