1; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=tahiti -verify-machineinstrs -amdgpu-load-store-vectorizer=0 < %s | FileCheck -check-prefix=SI -check-prefix=GCN -check-prefix=GCN-AA %s 2; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=bonaire -verify-machineinstrs -amdgpu-load-store-vectorizer=0 < %s | FileCheck -check-prefix=SI -check-prefix=GCN -check-prefix=GCN-AA %s 3 4; This test is mostly to test DAG store merging, so disable the vectorizer. 5; Run with devices with different unaligned load restrictions. 6 7; TODO: Vector element tests 8; TODO: Non-zero base offset for load and store combinations 9; TODO: Same base addrspacecasted 10 11 12; GCN-LABEL: {{^}}merge_global_store_2_constants_i8: 13; GCN: buffer_store_short 14; GCN: s_endpgm 15define amdgpu_kernel void @merge_global_store_2_constants_i8(i8 addrspace(1)* %out) #0 { 16 %out.gep.1 = getelementptr i8, i8 addrspace(1)* %out, i32 1 17 18 store i8 123, i8 addrspace(1)* %out.gep.1 19 store i8 456, i8 addrspace(1)* %out, align 2 20 ret void 21} 22 23; GCN-LABEL: {{^}}merge_global_store_2_constants_i8_natural_align: 24; GCN: buffer_store_byte 25; GCN: buffer_store_byte 26; GCN: s_endpgm 27define amdgpu_kernel void @merge_global_store_2_constants_i8_natural_align(i8 addrspace(1)* %out) #0 { 28 %out.gep.1 = getelementptr i8, i8 addrspace(1)* %out, i32 1 29 30 store i8 123, i8 addrspace(1)* %out.gep.1 31 store i8 456, i8 addrspace(1)* %out 32 ret void 33} 34 35; GCN-LABEL: {{^}}merge_global_store_2_constants_i16: 36; GCN: buffer_store_dword v 37define amdgpu_kernel void @merge_global_store_2_constants_i16(i16 addrspace(1)* %out) #0 { 38 %out.gep.1 = getelementptr i16, i16 addrspace(1)* %out, i32 1 39 40 store i16 123, i16 addrspace(1)* %out.gep.1 41 store i16 456, i16 addrspace(1)* %out, align 4 42 ret void 43} 44 45; GCN-LABEL: {{^}}merge_global_store_2_constants_0_i16: 46; GCN: buffer_store_dword v 47define amdgpu_kernel void @merge_global_store_2_constants_0_i16(i16 addrspace(1)* %out) #0 { 48 %out.gep.1 = getelementptr i16, i16 addrspace(1)* %out, i32 1 49 50 store i16 0, i16 addrspace(1)* %out.gep.1 51 store i16 0, i16 addrspace(1)* %out, align 4 52 ret void 53} 54 55; GCN-LABEL: {{^}}merge_global_store_2_constants_i16_natural_align: 56; GCN: buffer_store_short 57; GCN: buffer_store_short 58; GCN: s_endpgm 59define amdgpu_kernel void @merge_global_store_2_constants_i16_natural_align(i16 addrspace(1)* %out) #0 { 60 %out.gep.1 = getelementptr i16, i16 addrspace(1)* %out, i32 1 61 62 store i16 123, i16 addrspace(1)* %out.gep.1 63 store i16 456, i16 addrspace(1)* %out 64 ret void 65} 66 67; GCN-LABEL: {{^}}merge_global_store_2_constants_i32: 68; SI-DAG: v_mov_b32_e32 v[[LO:[0-9]+]], 0x1c8 69; SI-DAG: v_mov_b32_e32 v[[HI:[0-9]+]], 0x7b 70; GCN: buffer_store_dwordx2 v{{\[}}[[LO]]:[[HI]]{{\]}} 71define amdgpu_kernel void @merge_global_store_2_constants_i32(i32 addrspace(1)* %out) #0 { 72 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 1 73 74 store i32 123, i32 addrspace(1)* %out.gep.1 75 store i32 456, i32 addrspace(1)* %out 76 ret void 77} 78 79; GCN-LABEL: {{^}}merge_global_store_2_constants_i32_f32: 80; GCN: buffer_store_dwordx2 81define amdgpu_kernel void @merge_global_store_2_constants_i32_f32(i32 addrspace(1)* %out) #0 { 82 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 1 83 %out.gep.1.bc = bitcast i32 addrspace(1)* %out.gep.1 to float addrspace(1)* 84 store float 1.0, float addrspace(1)* %out.gep.1.bc 85 store i32 456, i32 addrspace(1)* %out 86 ret void 87} 88 89; GCN-LABEL: {{^}}merge_global_store_2_constants_f32_i32: 90; SI-DAG: v_mov_b32_e32 v[[VLO:[0-9]+]], 4.0 91; SI-DAG: v_mov_b32_e32 v[[VHI:[0-9]+]], 0x7b 92; GCN: buffer_store_dwordx2 v{{\[}}[[VLO]]:[[VHI]]{{\]}} 93define amdgpu_kernel void @merge_global_store_2_constants_f32_i32(float addrspace(1)* %out) #0 { 94 %out.gep.1 = getelementptr float, float addrspace(1)* %out, i32 1 95 %out.gep.1.bc = bitcast float addrspace(1)* %out.gep.1 to i32 addrspace(1)* 96 store i32 123, i32 addrspace(1)* %out.gep.1.bc 97 store float 4.0, float addrspace(1)* %out 98 ret void 99} 100 101; GCN-LABEL: {{^}}merge_global_store_4_constants_i32: 102; GCN-DAG: v_mov_b32_e32 v[[HI:[0-9]+]], 0x14d{{$}} 103; GCN-DAG: v_mov_b32_e32 v{{[0-9]+}}, 0x1c8{{$}} 104; GCN-DAG: v_mov_b32_e32 v{{[0-9]+}}, 0x7b{{$}} 105; GCN-DAG: v_mov_b32_e32 v[[LO:[0-9]+]], 0x4d2{{$}} 106; GCN: buffer_store_dwordx4 v{{\[}}[[LO]]:[[HI]]{{\]}} 107define amdgpu_kernel void @merge_global_store_4_constants_i32(i32 addrspace(1)* %out) #0 { 108 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 1 109 %out.gep.2 = getelementptr i32, i32 addrspace(1)* %out, i32 2 110 %out.gep.3 = getelementptr i32, i32 addrspace(1)* %out, i32 3 111 112 store i32 123, i32 addrspace(1)* %out.gep.1 113 store i32 456, i32 addrspace(1)* %out.gep.2 114 store i32 333, i32 addrspace(1)* %out.gep.3 115 store i32 1234, i32 addrspace(1)* %out 116 ret void 117} 118 119; GCN-LABEL: {{^}}merge_global_store_4_constants_f32_order: 120; GCN: buffer_store_dwordx4 121define amdgpu_kernel void @merge_global_store_4_constants_f32_order(float addrspace(1)* %out) #0 { 122 %out.gep.1 = getelementptr float, float addrspace(1)* %out, i32 1 123 %out.gep.2 = getelementptr float, float addrspace(1)* %out, i32 2 124 %out.gep.3 = getelementptr float, float addrspace(1)* %out, i32 3 125 126 store float 8.0, float addrspace(1)* %out 127 store float 1.0, float addrspace(1)* %out.gep.1 128 store float 2.0, float addrspace(1)* %out.gep.2 129 store float 4.0, float addrspace(1)* %out.gep.3 130 ret void 131} 132 133; First store is out of order. 134; GCN-LABEL: {{^}}merge_global_store_4_constants_f32: 135; GCN: buffer_store_dwordx4 136define amdgpu_kernel void @merge_global_store_4_constants_f32(float addrspace(1)* %out) #0 { 137 %out.gep.1 = getelementptr float, float addrspace(1)* %out, i32 1 138 %out.gep.2 = getelementptr float, float addrspace(1)* %out, i32 2 139 %out.gep.3 = getelementptr float, float addrspace(1)* %out, i32 3 140 141 store float 1.0, float addrspace(1)* %out.gep.1 142 store float 2.0, float addrspace(1)* %out.gep.2 143 store float 4.0, float addrspace(1)* %out.gep.3 144 store float 8.0, float addrspace(1)* %out 145 ret void 146} 147 148; GCN-LABEL: {{^}}merge_global_store_4_constants_mixed_i32_f32: 149; GCN-AA: buffer_store_dwordx4 v 150; GCN: s_endpgm 151define amdgpu_kernel void @merge_global_store_4_constants_mixed_i32_f32(float addrspace(1)* %out) #0 { 152 %out.gep.1 = getelementptr float, float addrspace(1)* %out, i32 1 153 %out.gep.2 = getelementptr float, float addrspace(1)* %out, i32 2 154 %out.gep.3 = getelementptr float, float addrspace(1)* %out, i32 3 155 156 %out.gep.1.bc = bitcast float addrspace(1)* %out.gep.1 to i32 addrspace(1)* 157 %out.gep.3.bc = bitcast float addrspace(1)* %out.gep.3 to i32 addrspace(1)* 158 159 store i32 11, i32 addrspace(1)* %out.gep.1.bc 160 store float 2.0, float addrspace(1)* %out.gep.2 161 store i32 17, i32 addrspace(1)* %out.gep.3.bc 162 store float 8.0, float addrspace(1)* %out 163 ret void 164} 165 166; GCN-LABEL: {{^}}merge_global_store_3_constants_i32: 167; SI-DAG: buffer_store_dwordx2 168; SI-DAG: buffer_store_dword 169; SI-NOT: buffer_store_dword 170; GCN: s_endpgm 171define amdgpu_kernel void @merge_global_store_3_constants_i32(i32 addrspace(1)* %out) #0 { 172 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 1 173 %out.gep.2 = getelementptr i32, i32 addrspace(1)* %out, i32 2 174 175 store i32 123, i32 addrspace(1)* %out.gep.1 176 store i32 456, i32 addrspace(1)* %out.gep.2 177 store i32 1234, i32 addrspace(1)* %out 178 ret void 179} 180 181; GCN-LABEL: {{^}}merge_global_store_2_constants_i64: 182; GCN: buffer_store_dwordx4 183define amdgpu_kernel void @merge_global_store_2_constants_i64(i64 addrspace(1)* %out) #0 { 184 %out.gep.1 = getelementptr i64, i64 addrspace(1)* %out, i64 1 185 186 store i64 123, i64 addrspace(1)* %out.gep.1 187 store i64 456, i64 addrspace(1)* %out 188 ret void 189} 190 191; GCN-LABEL: {{^}}merge_global_store_4_constants_i64: 192; GCN: buffer_store_dwordx4 193; GCN: buffer_store_dwordx4 194define amdgpu_kernel void @merge_global_store_4_constants_i64(i64 addrspace(1)* %out) #0 { 195 %out.gep.1 = getelementptr i64, i64 addrspace(1)* %out, i64 1 196 %out.gep.2 = getelementptr i64, i64 addrspace(1)* %out, i64 2 197 %out.gep.3 = getelementptr i64, i64 addrspace(1)* %out, i64 3 198 199 store i64 123, i64 addrspace(1)* %out.gep.1 200 store i64 456, i64 addrspace(1)* %out.gep.2 201 store i64 333, i64 addrspace(1)* %out.gep.3 202 store i64 1234, i64 addrspace(1)* %out 203 ret void 204} 205 206; GCN-LABEL: {{^}}merge_global_store_2_adjacent_loads_i32: 207; GCN: buffer_load_dwordx2 [[LOAD:v\[[0-9]+:[0-9]+\]]] 208; GCN: buffer_store_dwordx2 [[LOAD]] 209define amdgpu_kernel void @merge_global_store_2_adjacent_loads_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 { 210 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 1 211 %in.gep.1 = getelementptr i32, i32 addrspace(1)* %in, i32 1 212 213 %lo = load i32, i32 addrspace(1)* %in 214 %hi = load i32, i32 addrspace(1)* %in.gep.1 215 216 store i32 %lo, i32 addrspace(1)* %out 217 store i32 %hi, i32 addrspace(1)* %out.gep.1 218 ret void 219} 220 221; GCN-LABEL: {{^}}merge_global_store_2_adjacent_loads_i32_nonzero_base: 222; GCN: buffer_load_dwordx2 [[LOAD:v\[[0-9]+:[0-9]+\]]], off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:8 223; GCN: buffer_store_dwordx2 [[LOAD]], off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:8 224define amdgpu_kernel void @merge_global_store_2_adjacent_loads_i32_nonzero_base(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 { 225 %in.gep.0 = getelementptr i32, i32 addrspace(1)* %in, i32 2 226 %in.gep.1 = getelementptr i32, i32 addrspace(1)* %in, i32 3 227 228 %out.gep.0 = getelementptr i32, i32 addrspace(1)* %out, i32 2 229 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 3 230 %lo = load i32, i32 addrspace(1)* %in.gep.0 231 %hi = load i32, i32 addrspace(1)* %in.gep.1 232 233 store i32 %lo, i32 addrspace(1)* %out.gep.0 234 store i32 %hi, i32 addrspace(1)* %out.gep.1 235 ret void 236} 237 238; GCN-LABEL: {{^}}merge_global_store_2_adjacent_loads_shuffle_i32: 239; GCN: buffer_load_dword v 240; GCN: buffer_load_dword v 241; GCN: buffer_store_dword v 242; GCN: buffer_store_dword v 243define amdgpu_kernel void @merge_global_store_2_adjacent_loads_shuffle_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 { 244 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 1 245 %in.gep.1 = getelementptr i32, i32 addrspace(1)* %in, i32 1 246 247 %lo = load i32, i32 addrspace(1)* %in 248 %hi = load i32, i32 addrspace(1)* %in.gep.1 249 250 store i32 %hi, i32 addrspace(1)* %out 251 store i32 %lo, i32 addrspace(1)* %out.gep.1 252 ret void 253} 254 255; GCN-LABEL: {{^}}merge_global_store_4_adjacent_loads_i32: 256; GCN: buffer_load_dwordx4 [[LOAD:v\[[0-9]+:[0-9]+\]]] 257; GCN: buffer_store_dwordx4 [[LOAD]] 258define amdgpu_kernel void @merge_global_store_4_adjacent_loads_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 { 259 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 1 260 %out.gep.2 = getelementptr i32, i32 addrspace(1)* %out, i32 2 261 %out.gep.3 = getelementptr i32, i32 addrspace(1)* %out, i32 3 262 %in.gep.1 = getelementptr i32, i32 addrspace(1)* %in, i32 1 263 %in.gep.2 = getelementptr i32, i32 addrspace(1)* %in, i32 2 264 %in.gep.3 = getelementptr i32, i32 addrspace(1)* %in, i32 3 265 266 %x = load i32, i32 addrspace(1)* %in 267 %y = load i32, i32 addrspace(1)* %in.gep.1 268 %z = load i32, i32 addrspace(1)* %in.gep.2 269 %w = load i32, i32 addrspace(1)* %in.gep.3 270 271 store i32 %x, i32 addrspace(1)* %out 272 store i32 %y, i32 addrspace(1)* %out.gep.1 273 store i32 %z, i32 addrspace(1)* %out.gep.2 274 store i32 %w, i32 addrspace(1)* %out.gep.3 275 ret void 276} 277 278; GCN-LABEL: {{^}}merge_global_store_3_adjacent_loads_i32: 279; SI-DAG: buffer_load_dwordx2 280; SI-DAG: buffer_load_dword v 281; GCN: s_waitcnt 282; SI-DAG: buffer_store_dword v 283; SI-DAG: buffer_store_dwordx2 v 284; GCN: s_endpgm 285define amdgpu_kernel void @merge_global_store_3_adjacent_loads_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 { 286 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 1 287 %out.gep.2 = getelementptr i32, i32 addrspace(1)* %out, i32 2 288 %in.gep.1 = getelementptr i32, i32 addrspace(1)* %in, i32 1 289 %in.gep.2 = getelementptr i32, i32 addrspace(1)* %in, i32 2 290 291 %x = load i32, i32 addrspace(1)* %in 292 %y = load i32, i32 addrspace(1)* %in.gep.1 293 %z = load i32, i32 addrspace(1)* %in.gep.2 294 295 store i32 %x, i32 addrspace(1)* %out 296 store i32 %y, i32 addrspace(1)* %out.gep.1 297 store i32 %z, i32 addrspace(1)* %out.gep.2 298 ret void 299} 300 301; GCN-LABEL: {{^}}merge_global_store_4_adjacent_loads_f32: 302; GCN: buffer_load_dwordx4 [[LOAD:v\[[0-9]+:[0-9]+\]]] 303; GCN: buffer_store_dwordx4 [[LOAD]] 304define amdgpu_kernel void @merge_global_store_4_adjacent_loads_f32(float addrspace(1)* %out, float addrspace(1)* %in) #0 { 305 %out.gep.1 = getelementptr float, float addrspace(1)* %out, i32 1 306 %out.gep.2 = getelementptr float, float addrspace(1)* %out, i32 2 307 %out.gep.3 = getelementptr float, float addrspace(1)* %out, i32 3 308 %in.gep.1 = getelementptr float, float addrspace(1)* %in, i32 1 309 %in.gep.2 = getelementptr float, float addrspace(1)* %in, i32 2 310 %in.gep.3 = getelementptr float, float addrspace(1)* %in, i32 3 311 312 %x = load float, float addrspace(1)* %in 313 %y = load float, float addrspace(1)* %in.gep.1 314 %z = load float, float addrspace(1)* %in.gep.2 315 %w = load float, float addrspace(1)* %in.gep.3 316 317 store float %x, float addrspace(1)* %out 318 store float %y, float addrspace(1)* %out.gep.1 319 store float %z, float addrspace(1)* %out.gep.2 320 store float %w, float addrspace(1)* %out.gep.3 321 ret void 322} 323 324; GCN-LABEL: {{^}}merge_global_store_4_adjacent_loads_i32_nonzero_base: 325; GCN: buffer_load_dwordx4 [[LOAD:v\[[0-9]+:[0-9]+\]]], off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:44 326; GCN: buffer_store_dwordx4 [[LOAD]], off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:28 327define amdgpu_kernel void @merge_global_store_4_adjacent_loads_i32_nonzero_base(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 { 328 %in.gep.0 = getelementptr i32, i32 addrspace(1)* %in, i32 11 329 %in.gep.1 = getelementptr i32, i32 addrspace(1)* %in, i32 12 330 %in.gep.2 = getelementptr i32, i32 addrspace(1)* %in, i32 13 331 %in.gep.3 = getelementptr i32, i32 addrspace(1)* %in, i32 14 332 %out.gep.0 = getelementptr i32, i32 addrspace(1)* %out, i32 7 333 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 8 334 %out.gep.2 = getelementptr i32, i32 addrspace(1)* %out, i32 9 335 %out.gep.3 = getelementptr i32, i32 addrspace(1)* %out, i32 10 336 337 %x = load i32, i32 addrspace(1)* %in.gep.0 338 %y = load i32, i32 addrspace(1)* %in.gep.1 339 %z = load i32, i32 addrspace(1)* %in.gep.2 340 %w = load i32, i32 addrspace(1)* %in.gep.3 341 342 store i32 %x, i32 addrspace(1)* %out.gep.0 343 store i32 %y, i32 addrspace(1)* %out.gep.1 344 store i32 %z, i32 addrspace(1)* %out.gep.2 345 store i32 %w, i32 addrspace(1)* %out.gep.3 346 ret void 347} 348 349; GCN-LABEL: {{^}}merge_global_store_4_adjacent_loads_inverse_i32: 350; GCN: buffer_load_dwordx4 [[LOAD:v\[[0-9]+:[0-9]+\]]] 351; GCN: s_barrier 352; GCN: buffer_store_dwordx4 [[LOAD]] 353define amdgpu_kernel void @merge_global_store_4_adjacent_loads_inverse_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 { 354 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 1 355 %out.gep.2 = getelementptr i32, i32 addrspace(1)* %out, i32 2 356 %out.gep.3 = getelementptr i32, i32 addrspace(1)* %out, i32 3 357 %in.gep.1 = getelementptr i32, i32 addrspace(1)* %in, i32 1 358 %in.gep.2 = getelementptr i32, i32 addrspace(1)* %in, i32 2 359 %in.gep.3 = getelementptr i32, i32 addrspace(1)* %in, i32 3 360 361 %x = load i32, i32 addrspace(1)* %in 362 %y = load i32, i32 addrspace(1)* %in.gep.1 363 %z = load i32, i32 addrspace(1)* %in.gep.2 364 %w = load i32, i32 addrspace(1)* %in.gep.3 365 366 ; Make sure the barrier doesn't stop this 367 tail call void @llvm.amdgcn.s.barrier() #1 368 369 store i32 %w, i32 addrspace(1)* %out.gep.3 370 store i32 %z, i32 addrspace(1)* %out.gep.2 371 store i32 %y, i32 addrspace(1)* %out.gep.1 372 store i32 %x, i32 addrspace(1)* %out 373 374 ret void 375} 376 377; TODO: Re-packing of loaded register required. Maybe an IR pass 378; should catch this? 379 380; GCN-LABEL: {{^}}merge_global_store_4_adjacent_loads_shuffle_i32: 381; GCN: buffer_load_dword v 382; GCN: buffer_load_dword v 383; GCN: buffer_load_dword v 384; GCN: buffer_load_dword v 385; GCN: s_barrier 386; GCN: buffer_store_dword v 387; GCN: buffer_store_dword v 388; GCN: buffer_store_dword v 389; GCN: buffer_store_dword v 390define amdgpu_kernel void @merge_global_store_4_adjacent_loads_shuffle_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 { 391 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 1 392 %out.gep.2 = getelementptr i32, i32 addrspace(1)* %out, i32 2 393 %out.gep.3 = getelementptr i32, i32 addrspace(1)* %out, i32 3 394 %in.gep.1 = getelementptr i32, i32 addrspace(1)* %in, i32 1 395 %in.gep.2 = getelementptr i32, i32 addrspace(1)* %in, i32 2 396 %in.gep.3 = getelementptr i32, i32 addrspace(1)* %in, i32 3 397 398 %x = load i32, i32 addrspace(1)* %in 399 %y = load i32, i32 addrspace(1)* %in.gep.1 400 %z = load i32, i32 addrspace(1)* %in.gep.2 401 %w = load i32, i32 addrspace(1)* %in.gep.3 402 403 ; Make sure the barrier doesn't stop this 404 tail call void @llvm.amdgcn.s.barrier() #1 405 406 store i32 %w, i32 addrspace(1)* %out 407 store i32 %z, i32 addrspace(1)* %out.gep.1 408 store i32 %y, i32 addrspace(1)* %out.gep.2 409 store i32 %x, i32 addrspace(1)* %out.gep.3 410 411 ret void 412} 413 414; GCN-LABEL: {{^}}merge_global_store_4_adjacent_loads_i8: 415; GCN: buffer_load_dword [[LOAD:v[0-9]+]] 416; GCN: buffer_store_dword [[LOAD]] 417; GCN: s_endpgm 418define amdgpu_kernel void @merge_global_store_4_adjacent_loads_i8(i8 addrspace(1)* %out, i8 addrspace(1)* %in) #0 { 419 %out.gep.1 = getelementptr i8, i8 addrspace(1)* %out, i8 1 420 %out.gep.2 = getelementptr i8, i8 addrspace(1)* %out, i8 2 421 %out.gep.3 = getelementptr i8, i8 addrspace(1)* %out, i8 3 422 %in.gep.1 = getelementptr i8, i8 addrspace(1)* %in, i8 1 423 %in.gep.2 = getelementptr i8, i8 addrspace(1)* %in, i8 2 424 %in.gep.3 = getelementptr i8, i8 addrspace(1)* %in, i8 3 425 426 %x = load i8, i8 addrspace(1)* %in, align 4 427 %y = load i8, i8 addrspace(1)* %in.gep.1 428 %z = load i8, i8 addrspace(1)* %in.gep.2 429 %w = load i8, i8 addrspace(1)* %in.gep.3 430 431 store i8 %x, i8 addrspace(1)* %out, align 4 432 store i8 %y, i8 addrspace(1)* %out.gep.1 433 store i8 %z, i8 addrspace(1)* %out.gep.2 434 store i8 %w, i8 addrspace(1)* %out.gep.3 435 ret void 436} 437 438; GCN-LABEL: {{^}}merge_global_store_4_adjacent_loads_i8_natural_align: 439; GCN: buffer_load_ubyte 440; GCN: buffer_load_ubyte 441; GCN: buffer_load_ubyte 442; GCN: buffer_load_ubyte 443; GCN: buffer_store_byte 444; GCN: buffer_store_byte 445; GCN: buffer_store_byte 446; GCN: buffer_store_byte 447; GCN: s_endpgm 448define amdgpu_kernel void @merge_global_store_4_adjacent_loads_i8_natural_align(i8 addrspace(1)* %out, i8 addrspace(1)* %in) #0 { 449 %out.gep.1 = getelementptr i8, i8 addrspace(1)* %out, i8 1 450 %out.gep.2 = getelementptr i8, i8 addrspace(1)* %out, i8 2 451 %out.gep.3 = getelementptr i8, i8 addrspace(1)* %out, i8 3 452 %in.gep.1 = getelementptr i8, i8 addrspace(1)* %in, i8 1 453 %in.gep.2 = getelementptr i8, i8 addrspace(1)* %in, i8 2 454 %in.gep.3 = getelementptr i8, i8 addrspace(1)* %in, i8 3 455 456 %x = load i8, i8 addrspace(1)* %in 457 %y = load i8, i8 addrspace(1)* %in.gep.1 458 %z = load i8, i8 addrspace(1)* %in.gep.2 459 %w = load i8, i8 addrspace(1)* %in.gep.3 460 461 store i8 %x, i8 addrspace(1)* %out 462 store i8 %y, i8 addrspace(1)* %out.gep.1 463 store i8 %z, i8 addrspace(1)* %out.gep.2 464 store i8 %w, i8 addrspace(1)* %out.gep.3 465 ret void 466} 467 468; GCN-LABEL: {{^}}merge_global_store_4_vector_elts_loads_v4i32: 469; GCN: buffer_load_dwordx4 [[LOAD:v\[[0-9]+:[0-9]+\]]] 470; GCN: buffer_store_dwordx4 [[LOAD]] 471; GCN: s_endpgm 472define amdgpu_kernel void @merge_global_store_4_vector_elts_loads_v4i32(i32 addrspace(1)* %out, <4 x i32> addrspace(1)* %in) #0 { 473 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i32 1 474 %out.gep.2 = getelementptr i32, i32 addrspace(1)* %out, i32 2 475 %out.gep.3 = getelementptr i32, i32 addrspace(1)* %out, i32 3 476 %vec = load <4 x i32>, <4 x i32> addrspace(1)* %in 477 478 %x = extractelement <4 x i32> %vec, i32 0 479 %y = extractelement <4 x i32> %vec, i32 1 480 %z = extractelement <4 x i32> %vec, i32 2 481 %w = extractelement <4 x i32> %vec, i32 3 482 483 store i32 %x, i32 addrspace(1)* %out 484 store i32 %y, i32 addrspace(1)* %out.gep.1 485 store i32 %z, i32 addrspace(1)* %out.gep.2 486 store i32 %w, i32 addrspace(1)* %out.gep.3 487 ret void 488} 489 490; GCN-LABEL: {{^}}merge_local_store_2_constants_i8: 491; GCN: ds_write_b16 492; GCN: s_endpgm 493define amdgpu_kernel void @merge_local_store_2_constants_i8(i8 addrspace(3)* %out) #0 { 494 %out.gep.1 = getelementptr i8, i8 addrspace(3)* %out, i32 1 495 496 store i8 123, i8 addrspace(3)* %out.gep.1 497 store i8 456, i8 addrspace(3)* %out, align 2 498 ret void 499} 500 501; GCN-LABEL: {{^}}merge_local_store_2_constants_i32: 502; GCN-DAG: v_mov_b32_e32 v[[LO:[0-9]+]], 0x1c8 503; GCN-DAG: v_mov_b32_e32 v[[HI:[0-9]+]], 0x7b 504; GCN: ds_write2_b32 v{{[0-9]+}}, v[[LO]], v[[HI]] offset1:1{{$}} 505define amdgpu_kernel void @merge_local_store_2_constants_i32(i32 addrspace(3)* %out) #0 { 506 %out.gep.1 = getelementptr i32, i32 addrspace(3)* %out, i32 1 507 508 store i32 123, i32 addrspace(3)* %out.gep.1 509 store i32 456, i32 addrspace(3)* %out 510 ret void 511} 512 513; GCN-LABEL: {{^}}merge_local_store_4_constants_i32: 514; GCN-DAG: v_mov_b32_e32 [[K2:v[0-9]+]], 0x1c8 515; GCN-DAG: v_mov_b32_e32 [[K3:v[0-9]+]], 0x14d 516; GCN-DAG: ds_write2_b32 v{{[0-9]+}}, [[K2]], [[K3]] offset0:2 offset1:3 517 518; GCN-DAG: v_mov_b32_e32 [[K0:v[0-9]+]], 0x4d2 519; GCN-DAG: v_mov_b32_e32 [[K1:v[0-9]+]], 0x7b 520; GCN-DAG: ds_write2_b32 v{{[0-9]+}}, [[K0]], [[K1]] offset1:1 521 522; GCN: s_endpgm 523define amdgpu_kernel void @merge_local_store_4_constants_i32(i32 addrspace(3)* %out) #0 { 524 %out.gep.1 = getelementptr i32, i32 addrspace(3)* %out, i32 1 525 %out.gep.2 = getelementptr i32, i32 addrspace(3)* %out, i32 2 526 %out.gep.3 = getelementptr i32, i32 addrspace(3)* %out, i32 3 527 528 store i32 123, i32 addrspace(3)* %out.gep.1 529 store i32 456, i32 addrspace(3)* %out.gep.2 530 store i32 333, i32 addrspace(3)* %out.gep.3 531 store i32 1234, i32 addrspace(3)* %out 532 ret void 533} 534 535; GCN-LABEL: {{^}}merge_global_store_5_constants_i32: 536; GCN-DAG: v_mov_b32_e32 v[[LO:[0-9]+]], 9{{$}} 537; GCN-DAG: v_mov_b32_e32 v[[HI4:[0-9]+]], -12{{$}} 538; GCN: buffer_store_dwordx4 v{{\[}}[[LO]]:[[HI4]]{{\]}} 539; GCN: v_mov_b32_e32 v[[HI:[0-9]+]], 11{{$}} 540; GCN: buffer_store_dword v[[HI]] 541define amdgpu_kernel void @merge_global_store_5_constants_i32(i32 addrspace(1)* %out) { 542 store i32 9, i32 addrspace(1)* %out, align 4 543 %idx1 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 1 544 store i32 12, i32 addrspace(1)* %idx1, align 4 545 %idx2 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 2 546 store i32 16, i32 addrspace(1)* %idx2, align 4 547 %idx3 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 3 548 store i32 -12, i32 addrspace(1)* %idx3, align 4 549 %idx4 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 4 550 store i32 11, i32 addrspace(1)* %idx4, align 4 551 ret void 552} 553 554; GCN-LABEL: {{^}}merge_global_store_6_constants_i32: 555; GCN: buffer_store_dwordx4 556; GCN: buffer_store_dwordx2 557define amdgpu_kernel void @merge_global_store_6_constants_i32(i32 addrspace(1)* %out) { 558 store i32 13, i32 addrspace(1)* %out, align 4 559 %idx1 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 1 560 store i32 15, i32 addrspace(1)* %idx1, align 4 561 %idx2 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 2 562 store i32 62, i32 addrspace(1)* %idx2, align 4 563 %idx3 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 3 564 store i32 63, i32 addrspace(1)* %idx3, align 4 565 %idx4 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 4 566 store i32 11, i32 addrspace(1)* %idx4, align 4 567 %idx5 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 5 568 store i32 123, i32 addrspace(1)* %idx5, align 4 569 ret void 570} 571 572; GCN-LABEL: {{^}}merge_global_store_7_constants_i32: 573; GCN: buffer_store_dwordx4 574; GCN: buffer_store_dwordx2 575; GCN: buffer_store_dword v 576define amdgpu_kernel void @merge_global_store_7_constants_i32(i32 addrspace(1)* %out) { 577 store i32 34, i32 addrspace(1)* %out, align 4 578 %idx1 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 1 579 store i32 999, i32 addrspace(1)* %idx1, align 4 580 %idx2 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 2 581 store i32 65, i32 addrspace(1)* %idx2, align 4 582 %idx3 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 3 583 store i32 33, i32 addrspace(1)* %idx3, align 4 584 %idx4 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 4 585 store i32 98, i32 addrspace(1)* %idx4, align 4 586 %idx5 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 5 587 store i32 91, i32 addrspace(1)* %idx5, align 4 588 %idx6 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 6 589 store i32 212, i32 addrspace(1)* %idx6, align 4 590 ret void 591} 592 593; GCN-LABEL: {{^}}merge_global_store_8_constants_i32: 594; GCN: buffer_store_dwordx4 595; GCN: buffer_store_dwordx4 596; GCN: s_endpgm 597define amdgpu_kernel void @merge_global_store_8_constants_i32(i32 addrspace(1)* %out) { 598 store i32 34, i32 addrspace(1)* %out, align 4 599 %idx1 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 1 600 store i32 999, i32 addrspace(1)* %idx1, align 4 601 %idx2 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 2 602 store i32 65, i32 addrspace(1)* %idx2, align 4 603 %idx3 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 3 604 store i32 33, i32 addrspace(1)* %idx3, align 4 605 %idx4 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 4 606 store i32 98, i32 addrspace(1)* %idx4, align 4 607 %idx5 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 5 608 store i32 91, i32 addrspace(1)* %idx5, align 4 609 %idx6 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 6 610 store i32 212, i32 addrspace(1)* %idx6, align 4 611 %idx7 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 7 612 store i32 999, i32 addrspace(1)* %idx7, align 4 613 ret void 614} 615 616; This requires handling of scalar_to_vector for v2i64 to avoid 617; scratch usage. 618; FIXME: Should do single load and store 619 620; GCN-LABEL: {{^}}copy_v3i32_align4: 621; GCN-NOT: SCRATCH_RSRC_DWORD 622; GCN-DAG: buffer_load_dword v{{[0-9]+}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:8 623; GCN-DAG: buffer_load_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0{{$}} 624; GCN-NOT: offen 625; GCN: s_waitcnt vmcnt 626; GCN-NOT: offen 627; GCN-DAG: buffer_store_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0{{$}} 628; GCN-DAG: buffer_store_dword v{{[0-9]+}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:8 629 630; GCN: ScratchSize: 0{{$}} 631define amdgpu_kernel void @copy_v3i32_align4(<3 x i32> addrspace(1)* noalias %out, <3 x i32> addrspace(1)* noalias %in) #0 { 632 %vec = load <3 x i32>, <3 x i32> addrspace(1)* %in, align 4 633 store <3 x i32> %vec, <3 x i32> addrspace(1)* %out 634 ret void 635} 636 637; GCN-LABEL: {{^}}copy_v3i64_align4: 638; GCN-NOT: SCRATCH_RSRC_DWORD 639; GCN-DAG: buffer_load_dwordx4 v{{\[[0-9]+:[0-9]+\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0{{$}} 640; GCN-DAG: buffer_load_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:16{{$}} 641; GCN-NOT: offen 642; GCN: s_waitcnt vmcnt 643; GCN-NOT: offen 644; GCN-DAG: buffer_store_dwordx4 v{{\[[0-9]+:[0-9]+\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0{{$}} 645; GCN-DAG: buffer_store_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:16{{$}} 646; GCN: ScratchSize: 0{{$}} 647define amdgpu_kernel void @copy_v3i64_align4(<3 x i64> addrspace(1)* noalias %out, <3 x i64> addrspace(1)* noalias %in) #0 { 648 %vec = load <3 x i64>, <3 x i64> addrspace(1)* %in, align 4 649 store <3 x i64> %vec, <3 x i64> addrspace(1)* %out 650 ret void 651} 652 653; GCN-LABEL: {{^}}copy_v3f32_align4: 654; GCN-NOT: SCRATCH_RSRC_DWORD 655; GCN-DAG: buffer_load_dword v{{[0-9]+}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:8 656; GCN-DAG: buffer_load_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0{{$}} 657; GCN-NOT: offen 658; GCN: s_waitcnt vmcnt 659; GCN-NOT: offen 660; GCN-DAG: buffer_store_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0{{$}} 661; GCN-DAG: buffer_store_dword v{{[0-9]+}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:8 662; GCN: ScratchSize: 0{{$}} 663define amdgpu_kernel void @copy_v3f32_align4(<3 x float> addrspace(1)* noalias %out, <3 x float> addrspace(1)* noalias %in) #0 { 664 %vec = load <3 x float>, <3 x float> addrspace(1)* %in, align 4 665 %fadd = fadd <3 x float> %vec, <float 1.0, float 2.0, float 4.0> 666 store <3 x float> %fadd, <3 x float> addrspace(1)* %out 667 ret void 668} 669 670; GCN-LABEL: {{^}}copy_v3f64_align4: 671; GCN-NOT: SCRATCH_RSRC_DWORD 672; GCN-DAG: buffer_load_dwordx4 v{{\[[0-9]+:[0-9]+\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0{{$}} 673; GCN-DAG: buffer_load_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:16{{$}} 674; GCN-NOT: offen 675; GCN: s_waitcnt vmcnt 676; GCN-NOT: offen 677; GCN-DAG: buffer_store_dwordx4 v{{\[[0-9]+:[0-9]+\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0{{$}} 678; GCN-DAG: buffer_store_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:16{{$}} 679; GCN: ScratchSize: 0{{$}} 680define amdgpu_kernel void @copy_v3f64_align4(<3 x double> addrspace(1)* noalias %out, <3 x double> addrspace(1)* noalias %in) #0 { 681 %vec = load <3 x double>, <3 x double> addrspace(1)* %in, align 4 682 %fadd = fadd <3 x double> %vec, <double 1.0, double 2.0, double 4.0> 683 store <3 x double> %fadd, <3 x double> addrspace(1)* %out 684 ret void 685} 686 687declare void @llvm.amdgcn.s.barrier() #1 688 689attributes #0 = { nounwind } 690attributes #1 = { convergent nounwind } 691