Skip to content

Commit 72da47d

Browse files
committed
run post-RA hazard recognizer pass late
Memory legalizer, waitcnt, and shrink passes can perturb the instructions, which means that the post-RA hazard recognizer pass should run after them. Otherwise, one of those passes may invalidate the work done by the hazard recognizer. Note that this has adverse side-effect that any consecutive S_NOP 0's, emitted by the hazard recognizer, will not be shrunk into a single S_NOP <N>. This should be addressed in a follow-on patch. Differential Revision: https://reviews.llvm.org/D49288 llvm-svn: 337154
1 parent c2d5d9a commit 72da47d

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,10 @@ void GCNPassConfig::addPreSched2() {
886886
}
887887

888888
void GCNPassConfig::addPreEmitPass() {
889+
addPass(createSIMemoryLegalizerPass());
890+
addPass(createSIInsertWaitcntsPass());
891+
addPass(createSIShrinkInstructionsPass());
892+
889893
// The hazard recognizer that runs as part of the post-ra scheduler does not
890894
// guarantee to be able handle all hazards correctly. This is because if there
891895
// are multiple scheduling regions in a basic block, the regions are scheduled
@@ -894,11 +898,11 @@ void GCNPassConfig::addPreEmitPass() {
894898
//
895899
// Here we add a stand-alone hazard recognizer pass which can handle all
896900
// cases.
901+
//
902+
// FIXME: This stand-alone pass will emit indiv. S_NOP 0, as needed. It would
903+
// be better for it to emit S_NOP <N> when possible.
897904
addPass(&PostRAHazardRecognizerID);
898905

899-
addPass(createSIMemoryLegalizerPass());
900-
addPass(createSIInsertWaitcntsPass());
901-
addPass(createSIShrinkInstructionsPass());
902906
addPass(&SIInsertSkipsPassID);
903907
addPass(createSIDebuggerInsertNopsPass());
904908
addPass(&BranchRelaxationPassID);

llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ bool SIGfx6CacheControl::insertWait(MachineBasicBlock::iterator &MI,
737737
case SIAtomicScope::WAVEFRONT:
738738
case SIAtomicScope::SINGLETHREAD:
739739
// The L1 cache keeps all memory operations in order for
740-
// wavesfronts in the same work-group.
740+
// wavefronts in the same work-group.
741741
break;
742742
default:
743743
llvm_unreachable("Unsupported synchronization scope");

llvm/test/CodeGen/AMDGPU/llvm.amdgcn.mov.dpp.ll

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
; VI-LABEL: {{^}}dpp_test:
77
; VI: v_mov_b32_e32 v0, s{{[0-9]+}}
88
; VI-NOOPT: v_mov_b32_e32 v1, s{{[0-9]+}}
9-
; VI: s_nop 1
9+
; VI-OPT: s_nop 1
10+
; VI-NOOPT: s_nop 0
11+
; VI-NOOPT: s_nop 0
1012
; VI-OPT: v_mov_b32_dpp v0, v0 quad_perm:[1,0,0,0] row_mask:0x1 bank_mask:0x1 bound_ctrl:0 ; encoding: [0xfa,0x02,0x00,0x7e,0x00,0x01,0x08,0x11]
1113
; VI-NOOPT: v_mov_b32_dpp v0, v1 quad_perm:[1,0,0,0] row_mask:0x1 bank_mask:0x1 bound_ctrl:0 ; encoding: [0xfa,0x02,0x00,0x7e,0x01,0x01,0x08,0x11]
1214
define amdgpu_kernel void @dpp_test(i32 addrspace(1)* %out, i32 %in) {
@@ -18,10 +20,14 @@ define amdgpu_kernel void @dpp_test(i32 addrspace(1)* %out, i32 %in) {
1820
; VI-LABEL: {{^}}dpp_wait_states:
1921
; VI-NOOPT: v_mov_b32_e32 [[VGPR1:v[0-9]+]], s{{[0-9]+}}
2022
; VI: v_mov_b32_e32 [[VGPR0:v[0-9]+]], s{{[0-9]+}}
21-
; VI: s_nop 1
23+
; VI-OPT: s_nop 1
24+
; VI-NOOPT: s_nop 0
25+
; VI-NOOPT: s_nop 0
2226
; VI-OPT: v_mov_b32_dpp [[VGPR0]], [[VGPR0]] quad_perm:[1,0,0,0] row_mask:0x1 bank_mask:0x1 bound_ctrl:0
23-
; VI-NOOPT: v_mov_b32_dpp [[VGPR1]], [[VGPR0]] quad_perm:[1,0,0,0] row_mask:0x1 bank_mask:0x1 bound_ctrl:0
24-
; VI: s_nop 1
27+
; VI-NOOPT: v_mov_b32_dpp [[VGPR1]], [[VGPR0]] quad_perm:[1,0,0,0] row_mask:0x1 bank_mask:0x1 bound_ctrl:
28+
; VI-OPT: s_nop 1
29+
; VI-NOOPT: s_nop 0
30+
; VI-NOOPT: s_nop 0
2531
; VI-OPT: v_mov_b32_dpp v{{[0-9]+}}, [[VGPR0]] quad_perm:[1,0,0,0] row_mask:0x1 bank_mask:0x1 bound_ctrl:0
2632
; VI-NOOPT: v_mov_b32_dpp v{{[0-9]+}}, [[VGPR1]] quad_perm:[1,0,0,0] row_mask:0x1 bank_mask:0x1 bound_ctrl:0
2733
define amdgpu_kernel void @dpp_wait_states(i32 addrspace(1)* %out, i32 %in) {
@@ -35,11 +41,14 @@ define amdgpu_kernel void @dpp_wait_states(i32 addrspace(1)* %out, i32 %in) {
3541
; VI: ; %endif
3642
; VI-OPT: s_mov_b32
3743
; VI-OPT: s_mov_b32
38-
; VI-NOOPT: s_nop 1
44+
; VI-NOOPT: s_waitcnt
45+
; VI-NOOPT-NEXT: s_nop 0
3946
; VI: v_mov_b32_dpp [[VGPR0:v[0-9]+]], v{{[0-9]+}} quad_perm:[1,0,0,0] row_mask:0x1 bank_mask:0x1 bound_ctrl:0
40-
; VI: s_nop 1
47+
; VI-OPT: s_nop 1
4148
; VI: v_mov_b32_dpp [[VGPR1:v[0-9]+]], [[VGPR0]] quad_perm:[1,0,0,0] row_mask:0x1 bank_mask:0x1 bound_ctrl:0
42-
; VI: s_nop 1
49+
; VI-OPT: s_nop 1
50+
; VI-NOOPT: s_nop 0
51+
; VI-NOOPT: s_nop 0
4352
; VI: v_mov_b32_dpp v{{[0-9]+}}, [[VGPR1]] quad_perm:[1,0,0,0] row_mask:0x1 bank_mask:0x1 bound_ctrl:0
4453
define amdgpu_kernel void @dpp_first_in_bb(float addrspace(1)* %out, float addrspace(1)* %in, float %cond, float %a, float %b) {
4554
%cmp = fcmp oeq float %cond, 0.0

llvm/test/CodeGen/AMDGPU/llvm.amdgcn.update.dpp.ll

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,43 @@
44
; VI-LABEL: {{^}}dpp_test:
55
; VI: v_mov_b32_e32 v0, s{{[0-9]+}}
66
; VI: v_mov_b32_e32 v1, s{{[0-9]+}}
7-
; VI: s_nop 1
7+
; VI-OPT: s_nop 1
8+
; VI-NOOPT: s_nop 0
9+
; VI-NOOPT: s_nop 0
810
; VI: v_mov_b32_dpp v0, v1 quad_perm:[1,0,0,0] row_mask:0x1 bank_mask:0x1 bound_ctrl:0 ; encoding: [0xfa,0x02,0x00,0x7e,0x01,0x01,0x08,0x11]
911
define amdgpu_kernel void @dpp_test(i32 addrspace(1)* %out, i32 %in1, i32 %in2) {
1012
%tmp0 = call i32 @llvm.amdgcn.update.dpp.i32(i32 %in1, i32 %in2, i32 1, i32 1, i32 1, i1 1) #0
1113
store i32 %tmp0, i32 addrspace(1)* %out
1214
ret void
1315
}
1416

17+
; VI-LABEL: {{^}}dpp_test1:
18+
; VI-OPT: v_add_u32_e32 [[REG:v[0-9]+]], vcc, v{{[0-9]+}}, v{{[0-9]+}}
19+
; VI-NOOPT: v_mov_b32_e32 v{{[0-9]+}}, 0
20+
; VI-NOOPT: v_mov_b32_e32 [[REG:v[0-9]+]], v{{[0-9]+}}
21+
; VI-NEXT: s_nop 0
22+
; VI-NEXT: s_nop 0
23+
; VI-NEXT: v_mov_b32_dpp v2, [[REG]] quad_perm:[1,0,3,2] row_mask:0xf bank_mask:0xf
24+
@0 = internal unnamed_addr addrspace(3) global [448 x i32] undef, align 4
25+
define weak_odr amdgpu_kernel void @dpp_test1(i32* %arg) local_unnamed_addr {
26+
bb:
27+
%tmp = tail call i32 @llvm.amdgcn.workitem.id.x()
28+
%tmp1 = zext i32 %tmp to i64
29+
%tmp2 = getelementptr inbounds [448 x i32], [448 x i32] addrspace(3)* @0, i32 0, i32 %tmp
30+
%tmp3 = load i32, i32 addrspace(3)* %tmp2, align 4
31+
fence syncscope("workgroup") release
32+
tail call void @llvm.amdgcn.s.barrier()
33+
fence syncscope("workgroup") acquire
34+
%tmp4 = add nsw i32 %tmp3, %tmp3
35+
%tmp5 = tail call i32 @llvm.amdgcn.update.dpp.i32(i32 0, i32 %tmp4, i32 177, i32 15, i32 15, i1 zeroext false)
36+
%tmp6 = add nsw i32 %tmp5, %tmp4
37+
%tmp7 = getelementptr inbounds i32, i32* %arg, i64 %tmp1
38+
store i32 %tmp6, i32* %tmp7, align 4
39+
ret void
40+
}
41+
42+
declare i32 @llvm.amdgcn.workitem.id.x()
43+
declare void @llvm.amdgcn.s.barrier()
1544
declare i32 @llvm.amdgcn.update.dpp.i32(i32, i32, i32, i32, i32, i1) #0
1645

1746
attributes #0 = { nounwind readnone convergent }

llvm/test/CodeGen/AMDGPU/memory_clause.ll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ bb:
7777
; GCN-NEXT: buffer_load_dword
7878
; GCN-NEXT: buffer_load_dword
7979
; GCN-NEXT: s_nop
80+
; GCN-NEXT: s_nop
8081
; GCN-NEXT: buffer_load_dword
8182
define void @mubuf_clause(<4 x i32> addrspace(5)* noalias nocapture readonly %arg, <4 x i32> addrspace(5)* noalias nocapture %arg1) {
8283
bb:
@@ -105,8 +106,9 @@ bb:
105106

106107
; GCN-LABEL: {{^}}vector_clause_indirect:
107108
; GCN: global_load_dwordx2 [[ADDR:v\[[0-9:]+\]]], v[{{[0-9:]+}}], off
108-
; GCN-NEXT: s_nop
109+
; GCN-NEXT: s_nop 0
109110
; GCN-NEXT: s_waitcnt vmcnt(0)
111+
; GCN-NEXT: s_nop 0
110112
; GCN-NEXT: global_load_dwordx4 v[{{[0-9:]+}}], [[ADDR]], off
111113
; GCN-NEXT: global_load_dwordx4 v[{{[0-9:]+}}], [[ADDR]], off offset:16
112114
define amdgpu_kernel void @vector_clause_indirect(i64 addrspace(1)* noalias nocapture readonly %arg, <4 x i32> addrspace(1)* noalias nocapture readnone %arg1, <4 x i32> addrspace(1)* noalias nocapture %arg2) {
@@ -128,6 +130,7 @@ bb:
128130
; GCN-LABEL: {{^}}load_global_d16_hi:
129131
; GCN: global_load_short_d16_hi v
130132
; GCN-NEXT: s_nop
133+
; GCN-NEXT: s_nop
131134
; GCN-NEXT: global_load_short_d16_hi v
132135
define void @load_global_d16_hi(i16 addrspace(1)* %in, i16 %reg, <2 x i16> addrspace(1)* %out) {
133136
entry:
@@ -147,6 +150,7 @@ entry:
147150
; GCN-LABEL: {{^}}load_global_d16_lo:
148151
; GCN: global_load_short_d16 v
149152
; GCN-NEXT: s_nop
153+
; GCN-NEXT: s_nop
150154
; GCN-NEXT: global_load_short_d16 v
151155
define void @load_global_d16_lo(i16 addrspace(1)* %in, i32 %reg, <2 x i16> addrspace(1)* %out) {
152156
entry:

0 commit comments

Comments
 (0)