1 ; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -o - -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,LOOP %s
2 ; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=hawaii -o - -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,LOOP %s
3 ; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=fiji -o - -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,LOOP %s
4 ; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx900 -o - -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,NOLOOP %s
5 ; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx1010 -o - -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,NOLOOP %s
8 ; GCN-LABEL: {{^}}gws_init_offset0:
9 ; GCN-DAG: s_load_dword [[BAR_NUM:s[0-9]+]]
10 ; GCN-DAG: s_mov_b32 m0, 0{{$}}
11 ; GCN: v_mov_b32_e32 v0, [[BAR_NUM]]
12 ; NOLOOP: ds_gws_init v0 gds{{$}}
14 ; LOOP: [[LOOP:BB[0-9]+_[0-9]+]]:
15 ; LOOP-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_TRAPSTS, 8, 1), 0
16 ; LOOP-NEXT: ds_gws_init v0 gds
17 ; LOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
18 ; LOOP-NEXT: s_getreg_b32 [[GETREG:s[0-9]+]], hwreg(HW_REG_TRAPSTS, 8, 1)
19 ; LOOP-NEXT: s_cmp_lg_u32 [[GETREG]], 0
20 ; LOOP-NEXT: s_cbranch_scc1 [[LOOP]]
21 define amdgpu_kernel void @gws_init_offset0(i32 %val) #0 {
22 call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 0)
27 ; GCN-LABEL: {{^}}gws_init_offset63:
28 ; NOLOOP-DAG: s_load_dword [[BAR_NUM:s[0-9]+]]
29 ; NOLOOP-DAG: s_mov_b32 m0, 0{{$}}
30 ; NOLOOP-DAG: v_mov_b32_e32 v0, [[BAR_NUM]]
31 ; NOLOOP: ds_gws_init v0 offset:63 gds{{$}}
34 ; LOOP: s_mov_b32 m0, 0{{$}}
35 ; LOOP: [[LOOP:BB[0-9]+_[0-9]+]]:
36 ; LOOP-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_TRAPSTS, 8, 1), 0
37 ; LOOP-NEXT: ds_gws_init v0 offset:63 gds
38 ; LOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
39 ; LOOP-NEXT: s_getreg_b32 [[GETREG:s[0-9]+]], hwreg(HW_REG_TRAPSTS, 8, 1)
40 ; LOOP-NEXT: s_cmp_lg_u32 [[GETREG]], 0
41 ; LOOP-NEXT: s_cbranch_scc1 [[LOOP]]
42 define amdgpu_kernel void @gws_init_offset63(i32 %val) #0 {
43 call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 63)
47 ; FIXME: Should be able to shift directly into m0
48 ; GCN-LABEL: {{^}}gws_init_sgpr_offset:
49 ; NOLOOP-DAG: s_load_dwordx2 s{{\[}}[[BAR_NUM:[0-9]+]]:[[OFFSET:[0-9]+]]{{\]}}
50 ; NOLOOP-DAG: s_lshl_b32 [[SHL:s[0-9]+]], s[[OFFSET]], 16
51 ; NOLOOP-DAG: s_mov_b32 m0, [[SHL]]{{$}}
52 ; NOLOOP-DAG: v_mov_b32_e32 [[GWS_VAL:v[0-9]+]], s[[BAR_NUM]]
53 ; NOLOOP: ds_gws_init [[GWS_VAL]] gds{{$}}
54 define amdgpu_kernel void @gws_init_sgpr_offset(i32 %val, i32 %offset) #0 {
55 call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 %offset)
59 ; Variable offset in SGPR with constant add
60 ; GCN-LABEL: {{^}}gws_init_sgpr_offset_add1:
61 ; NOLOOP-DAG: s_load_dwordx2 s{{\[}}[[BAR_NUM:[0-9]+]]:[[OFFSET:[0-9]+]]{{\]}}
62 ; NOLOOP-DAG: s_lshl_b32 [[SHL:s[0-9]+]], s[[OFFSET]], 16
63 ; NOLOOP-DAG: s_mov_b32 m0, [[SHL]]{{$}}
64 ; NOLOOP-DAG: v_mov_b32_e32 [[GWS_VAL:v[0-9]+]], s[[BAR_NUM]]
65 ; NOLOOP: ds_gws_init [[GWS_VAL]] offset:1 gds{{$}}
66 define amdgpu_kernel void @gws_init_sgpr_offset_add1(i32 %val, i32 %offset.base) #0 {
67 %offset = add i32 %offset.base, 1
68 call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 %offset)
72 ; GCN-LABEL: {{^}}gws_init_vgpr_offset:
73 ; NOLOOP-DAG: s_load_dword [[BAR_NUM:s[0-9]+]]
74 ; NOLOOP-DAG: v_readfirstlane_b32 [[READLANE:s[0-9]+]], v0
75 ; NOLOOP-DAG: s_lshl_b32 [[SHL:s[0-9]+]], [[READLANE]], 16
76 ; NOLOOP-DAG: s_mov_b32 m0, [[SHL]]{{$}}
77 ; NOLOOP-DAG: v_mov_b32_e32 v0, [[BAR_NUM]]
78 ; NOLOOP: ds_gws_init v0 gds{{$}}
79 define amdgpu_kernel void @gws_init_vgpr_offset(i32 %val) #0 {
80 %vgpr.offset = call i32 @llvm.amdgcn.workitem.id.x()
81 call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 %vgpr.offset)
85 ; Variable offset in VGPR with constant add
86 ; GCN-LABEL: {{^}}gws_init_vgpr_offset_add:
87 ; NOLOOP-DAG: s_load_dword [[BAR_NUM:s[0-9]+]]
88 ; NOLOOP-DAG: v_readfirstlane_b32 [[READLANE:s[0-9]+]], v0
89 ; NOLOOP-DAG: s_lshl_b32 [[SHL:s[0-9]+]], [[READLANE]], 16
90 ; NOLOOP-DAG: s_mov_b32 m0, [[SHL]]{{$}}
91 ; NOLOOP-DAG: v_mov_b32_e32 v0, [[BAR_NUM]]
92 ; NOLOOP: ds_gws_init v0 offset:3 gds{{$}}
93 define amdgpu_kernel void @gws_init_vgpr_offset_add(i32 %val) #0 {
94 %vgpr.offset.base = call i32 @llvm.amdgcn.workitem.id.x()
95 %vgpr.offset = add i32 %vgpr.offset.base, 3
96 call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 %vgpr.offset)
100 @lds = internal unnamed_addr addrspace(3) global i32 undef
102 ; Check if m0 initialization is shared.
103 ; GCN-LABEL: {{^}}gws_init_save_m0_init_constant_offset:
104 ; NOLOOP: s_mov_b32 m0, 0
105 ; NOLOOP: ds_gws_init v{{[0-9]+}} offset:10 gds
107 ; LOOP: s_mov_b32 m0, -1
109 ; LOOP: s_mov_b32 m0, 0
110 ; LOOP: s_setreg_imm32_b32
111 ; LOOP: ds_gws_init v{{[0-9]+}} offset:10 gds
112 ; LOOP: s_cbranch_scc1
114 ; LOOP: s_mov_b32 m0, -1
116 define amdgpu_kernel void @gws_init_save_m0_init_constant_offset(i32 %val) #0 {
117 store volatile i32 1, i32 addrspace(3)* @lds
118 call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 10)
119 store i32 2, i32 addrspace(3)* @lds
123 ; GCN-LABEL: {{^}}gws_init_lgkmcnt:
124 ; NOLOOP: s_mov_b32 m0, 0{{$}}
125 ; NOLOOP: ds_gws_init v0 gds{{$}}
126 ; NOLOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
127 ; NOLOOP-NEXT: s_setpc_b64
128 define void @gws_init_lgkmcnt(i32 %val) {
129 call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 0)
133 ; Does not imply memory fence on its own
134 ; GCN-LABEL: {{^}}gws_init_wait_before:
135 ; NOLOOP: s_waitcnt lgkmcnt(0)
136 ; NOLOOP-NOT: s_waitcnt
137 ; NOLOOP: ds_gws_init
138 ; NOLOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
139 define amdgpu_kernel void @gws_init_wait_before(i32 %val, i32 addrspace(1)* %ptr) #0 {
140 store i32 0, i32 addrspace(1)* %ptr
141 call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 7)
145 declare void @llvm.amdgcn.ds.gws.init(i32, i32) #1
146 declare i32 @llvm.amdgcn.workitem.id.x() #2
148 attributes #0 = { nounwind }
149 attributes #1 = { convergent inaccessiblememonly nounwind writeonly }
150 attributes #2 = { nounwind readnone speculatable }