| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 
 | ; RUN: llc -mtriple=amdgcn -mcpu=gfx802  -asm-verbose=0 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GFX8,GFX8_9 %s
; RUN: llc -mtriple=amdgcn -mcpu=gfx900  -asm-verbose=0 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GFX9,GFX9PLUS,GFX8_9 %s
; RUN: llc -mtriple=amdgcn -mcpu=gfx1010 -mattr=-back-off-barrier -asm-verbose=0 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GFX10PLUS,GFX9PLUS %s
; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=-back-off-barrier -asm-verbose=0 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GFX10PLUS,GFX9PLUS %s
; GCN-LABEL: barrier_vmcnt_global:
; GFX8:         flat_load_dword
; GFX9PLUS:     global_load_{{dword|b32}}
; GFX8:         s_waitcnt vmcnt(0){{$}}
; GFX9PLUS:     s_waitcnt vmcnt(0){{$}}
; GCN-NEXT:     s_barrier
define amdgpu_kernel void @barrier_vmcnt_global(ptr addrspace(1) %arg) {
bb:
  %tmp = tail call i32 @llvm.amdgcn.workitem.id.x()
  %tmp1 = zext i32 %tmp to i64
  %tmp2 = shl nuw nsw i64 %tmp1, 32
  %tmp3 = getelementptr inbounds i32, ptr addrspace(1) %arg, i64 %tmp1
  %tmp4 = load i32, ptr addrspace(1) %tmp3, align 4
  fence syncscope("singlethread") release
  tail call void @llvm.amdgcn.s.barrier()
  fence syncscope("singlethread") acquire
  %tmp5 = add nuw nsw i64 %tmp2, 4294967296
  %tmp6 = lshr exact i64 %tmp5, 32
  %tmp7 = getelementptr inbounds i32, ptr addrspace(1) %arg, i64 %tmp6
  store i32 %tmp4, ptr addrspace(1) %tmp7, align 4
  ret void
}
; GCN-LABEL: barrier_vscnt_global:
; GFX8:       flat_store_dword
; GFX9PLUS:   global_store_{{dword|b32}}
; GFX8:       s_waitcnt vmcnt(0){{$}}
; GFX9:       s_waitcnt vmcnt(0){{$}}
; GFX10PLUS:  s_waitcnt_vscnt null, 0x0
; GCN-NEXT:   s_barrier
define amdgpu_kernel void @barrier_vscnt_global(ptr addrspace(1) %arg) {
bb:
  %tmp = tail call i32 @llvm.amdgcn.workitem.id.x()
  %tmp1 = zext i32 %tmp to i64
  %tmp2 = shl nuw nsw i64 %tmp1, 32
  %tmp3 = add nuw nsw i64 %tmp2, 8589934592
  %tmp4 = lshr exact i64 %tmp3, 32
  %tmp5 = getelementptr inbounds i32, ptr addrspace(1) %arg, i64 %tmp4
  store i32 0, ptr addrspace(1) %tmp5, align 4
  fence syncscope("singlethread") release
  tail call void @llvm.amdgcn.s.barrier()
  fence syncscope("singlethread") acquire
  %tmp6 = add nuw nsw i64 %tmp2, 4294967296
  %tmp7 = lshr exact i64 %tmp6, 32
  %tmp8 = getelementptr inbounds i32, ptr addrspace(1) %arg, i64 %tmp7
  store i32 1, ptr addrspace(1) %tmp8, align 4
  ret void
}
; GCN-LABEL: barrier_vmcnt_vscnt_global:
; GFX8:         flat_load_dword
; GFX9PLUS:     global_load_{{dword|b32}}
; GFX8:         s_waitcnt vmcnt(0){{$}}
; GFX9PLUS:     s_waitcnt vmcnt(0){{$}}
; GFX10PLUS:    s_waitcnt_vscnt null, 0x0
; GCN-NEXT:     s_barrier
define amdgpu_kernel void @barrier_vmcnt_vscnt_global(ptr addrspace(1) %arg) {
bb:
  %tmp = tail call i32 @llvm.amdgcn.workitem.id.x()
  %tmp1 = zext i32 %tmp to i64
  %tmp2 = shl nuw nsw i64 %tmp1, 32
  %tmp3 = add nuw nsw i64 %tmp2, 8589934592
  %tmp4 = lshr exact i64 %tmp3, 32
  %tmp5 = getelementptr inbounds i32, ptr addrspace(1) %arg, i64 %tmp4
  store i32 0, ptr addrspace(1) %tmp5, align 4
  %tmp6 = getelementptr inbounds i32, ptr addrspace(1) %arg, i64 %tmp1
  %tmp7 = load i32, ptr addrspace(1) %tmp6, align 4
  fence syncscope("singlethread") release
  tail call void @llvm.amdgcn.s.barrier()
  fence syncscope("singlethread") acquire
  %tmp8 = add nuw nsw i64 %tmp2, 4294967296
  %tmp9 = lshr exact i64 %tmp8, 32
  %tmp10 = getelementptr inbounds i32, ptr addrspace(1) %arg, i64 %tmp9
  store i32 %tmp7, ptr addrspace(1) %tmp10, align 4
  ret void
}
; GCN-LABEL: barrier_vmcnt_flat:
; GCN:      flat_load_{{dword|b32}}
; GCN:      s_waitcnt vmcnt(0) lgkmcnt(0){{$}}
; GCN-NEXT: s_barrier
define amdgpu_kernel void @barrier_vmcnt_flat(ptr %arg) {
bb:
  %tmp = tail call i32 @llvm.amdgcn.workitem.id.x()
  %tmp1 = zext i32 %tmp to i64
  %tmp2 = shl nuw nsw i64 %tmp1, 32
  %tmp3 = getelementptr inbounds i32, ptr %arg, i64 %tmp1
  %tmp4 = load i32, ptr %tmp3, align 4
  fence syncscope("singlethread") release
  tail call void @llvm.amdgcn.s.barrier()
  fence syncscope("singlethread") acquire
  %tmp5 = add nuw nsw i64 %tmp2, 4294967296
  %tmp6 = lshr exact i64 %tmp5, 32
  %tmp7 = getelementptr inbounds i32, ptr %arg, i64 %tmp6
  store i32 %tmp4, ptr %tmp7, align 4
  ret void
}
; GCN-LABEL: barrier_vscnt_flat:
; GCN:         flat_store_{{dword|b32}}
; GFX8_9:      s_waitcnt vmcnt(0) lgkmcnt(0){{$}}
; GFX10PLUS:   s_waitcnt lgkmcnt(0){{$}}
; GFX10PLUS:   s_waitcnt_vscnt null, 0x0
; GCN-NEXT:    s_barrier
define amdgpu_kernel void @barrier_vscnt_flat(ptr %arg) {
bb:
  %tmp = tail call i32 @llvm.amdgcn.workitem.id.x()
  %tmp1 = zext i32 %tmp to i64
  %tmp2 = shl nuw nsw i64 %tmp1, 32
  %tmp3 = add nuw nsw i64 %tmp2, 8589934592
  %tmp4 = lshr exact i64 %tmp3, 32
  %tmp5 = getelementptr inbounds i32, ptr %arg, i64 %tmp4
  store i32 0, ptr %tmp5, align 4
  fence syncscope("singlethread") release
  tail call void @llvm.amdgcn.s.barrier()
  fence syncscope("singlethread") acquire
  %tmp6 = add nuw nsw i64 %tmp2, 4294967296
  %tmp7 = lshr exact i64 %tmp6, 32
  %tmp8 = getelementptr inbounds i32, ptr %arg, i64 %tmp7
  store i32 1, ptr %tmp8, align 4
  ret void
}
; GCN-LABEL: barrier_vmcnt_vscnt_flat:
; GCN:        flat_load_{{dword|b32}}
; GCN:        s_waitcnt vmcnt(0) lgkmcnt(0){{$}}
; GFX10PLUS:  s_waitcnt_vscnt null, 0x0
; GCN-NEXT:   s_barrier
define amdgpu_kernel void @barrier_vmcnt_vscnt_flat(ptr %arg) {
bb:
  %tmp = tail call i32 @llvm.amdgcn.workitem.id.x()
  %tmp1 = zext i32 %tmp to i64
  %tmp2 = shl nuw nsw i64 %tmp1, 32
  %tmp3 = add nuw nsw i64 %tmp2, 8589934592
  %tmp4 = lshr exact i64 %tmp3, 32
  %tmp5 = getelementptr inbounds i32, ptr %arg, i64 %tmp4
  store i32 0, ptr %tmp5, align 4
  %tmp6 = getelementptr inbounds i32, ptr %arg, i64 %tmp1
  %tmp7 = load i32, ptr %tmp6, align 4
  fence syncscope("singlethread") release
  tail call void @llvm.amdgcn.s.barrier()
  fence syncscope("singlethread") acquire
  %tmp8 = add nuw nsw i64 %tmp2, 4294967296
  %tmp9 = lshr exact i64 %tmp8, 32
  %tmp10 = getelementptr inbounds i32, ptr %arg, i64 %tmp9
  store i32 %tmp7, ptr %tmp10, align 4
  ret void
}
; GCN-LABEL: barrier_vmcnt_vscnt_flat_workgroup:
; GCN:        flat_load_{{dword|b32}}
; GFX8_9:     s_waitcnt lgkmcnt(0){{$}}
; GFX8_9:     s_waitcnt vmcnt(0){{$}}
; GFX10PLUS:  s_waitcnt vmcnt(0) lgkmcnt(0){{$}}
; GFX10PLUS:  s_waitcnt_vscnt null, 0x0
; GCN-NEXT:   s_barrier
define amdgpu_kernel void @barrier_vmcnt_vscnt_flat_workgroup(ptr %arg) {
bb:
  %tmp = tail call i32 @llvm.amdgcn.workitem.id.x()
  %tmp1 = zext i32 %tmp to i64
  %tmp2 = shl nuw nsw i64 %tmp1, 32
  %tmp3 = add nuw nsw i64 %tmp2, 8589934592
  %tmp4 = lshr exact i64 %tmp3, 32
  %tmp5 = getelementptr inbounds i32, ptr %arg, i64 %tmp4
  store i32 0, ptr %tmp5, align 4
  %tmp6 = getelementptr inbounds i32, ptr %arg, i64 %tmp1
  %tmp7 = load i32, ptr %tmp6, align 4
  fence syncscope("workgroup") release
  tail call void @llvm.amdgcn.s.barrier()
  fence syncscope("workgroup") acquire
  %tmp8 = add nuw nsw i64 %tmp2, 4294967296
  %tmp9 = lshr exact i64 %tmp8, 32
  %tmp10 = getelementptr inbounds i32, ptr %arg, i64 %tmp9
  store i32 %tmp7, ptr %tmp10, align 4
  ret void
}
; GCN-LABEL: load_vmcnt_global:
; GFX8:     flat_load_dword
; GFX9PLUS: global_load_{{dword|b32}}
; GFX8:     s_waitcnt vmcnt(0){{$}}
; GFX9PLUS: s_waitcnt vmcnt(0){{$}}
; GCN-NEXT: {{global|flat}}_store_{{dword|b32}}
define amdgpu_kernel void @load_vmcnt_global(ptr addrspace(1) %arg) {
bb:
  %tmp = tail call i32 @llvm.amdgcn.workitem.id.x()
  %tmp1 = zext i32 %tmp to i64
  %tmp2 = shl nuw nsw i64 %tmp1, 32
  %tmp3 = getelementptr inbounds i32, ptr addrspace(1) %arg, i64 %tmp1
  %tmp4 = load i32, ptr addrspace(1) %tmp3, align 4
  %tmp5 = add nuw nsw i64 %tmp2, 4294967296
  %tmp6 = lshr exact i64 %tmp5, 32
  %tmp7 = getelementptr inbounds i32, ptr addrspace(1) %arg, i64 %tmp6
  store i32 %tmp4, ptr addrspace(1) %tmp7, align 4
  ret void
}
; GCN-LABEL: load_vmcnt_flat:
; GCN:      flat_load_{{dword|b32}}
; GCN-NOT:  vscnt
; GCN:      s_waitcnt vmcnt(0) lgkmcnt(0){{$}}
; GCN-NEXT: {{global|flat}}_store_{{dword|b32}}
define amdgpu_kernel void @load_vmcnt_flat(ptr %arg) {
bb:
  %tmp = tail call i32 @llvm.amdgcn.workitem.id.x()
  %tmp1 = zext i32 %tmp to i64
  %tmp2 = shl nuw nsw i64 %tmp1, 32
  %tmp3 = getelementptr inbounds i32, ptr %arg, i64 %tmp1
  %tmp4 = load i32, ptr %tmp3, align 4
  %tmp5 = add nuw nsw i64 %tmp2, 4294967296
  %tmp6 = lshr exact i64 %tmp5, 32
  %tmp7 = getelementptr inbounds i32, ptr %arg, i64 %tmp6
  store i32 %tmp4, ptr %tmp7, align 4
  ret void
}
; GCN-LABEL: store_vscnt_private:
; GCN:         {{buffer|scratch}}_store_{{dword|b32}}
; GFX8_9:      s_waitcnt vmcnt(0)
; GCN-NEXT:    s_setpc_b64
define void @store_vscnt_private(ptr addrspace(5) %p) {
  store i32 0, ptr addrspace(5) %p
  ret void
}
; GCN-LABEL: store_vscnt_global:
; GFX8:        flat_store_dword
; GFX9PLUS:    global_store_{{dword|b32}}
; GFX8_9:      s_waitcnt vmcnt(0)
; GCN-NEXT:    s_setpc_b64
define void @store_vscnt_global(ptr addrspace(1) %p) {
  store i32 0, ptr addrspace(1) %p
  ret void
}
; GCN-LABEL: store_vscnt_flat:
; GCN:         flat_store_{{dword|b32}}
; GFX8_9:      s_waitcnt vmcnt(0) lgkmcnt(0){{$}}
; GFX10PLUS:   s_waitcnt lgkmcnt(0){{$}}
; GCN-NEXT:    s_setpc_b64
define void @store_vscnt_flat(ptr %p) {
  store i32 0, ptr %p
  ret void
}
; GCN-LABEL: function_prologue:
; GCN:        s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0){{$}}
; GCN-NEXT:   s_setpc_b64
define void @function_prologue() {
  ret void
}
declare void @llvm.amdgcn.s.barrier()
declare i32 @llvm.amdgcn.workitem.id.x()
 |