Skip to content

Commit b263033

Browse files
authored
AMDGPU: Remove arbitrary SCC liveness scan threshold (#94097)
1 parent 4c6367b commit b263033

File tree

2 files changed

+167
-2
lines changed

2 files changed

+167
-2
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6437,8 +6437,13 @@ loadMBUFScalarOperandsFromVGPR(const SIInstrInfo &TII, MachineInstr &MI,
64376437

64386438
// Save SCC. Waterfall Loop may overwrite SCC.
64396439
Register SaveSCCReg;
6440-
bool SCCNotDead = (MBB.computeRegisterLiveness(TRI, AMDGPU::SCC, MI, 30) !=
6441-
MachineBasicBlock::LQR_Dead);
6440+
6441+
// FIXME: We should maintain SCC liveness while doing the FixSGPRCopies walk
6442+
// rather than unlimited scan everywhere
6443+
bool SCCNotDead =
6444+
MBB.computeRegisterLiveness(TRI, AMDGPU::SCC, MI,
6445+
std::numeric_limits<unsigned>::max()) !=
6446+
MachineBasicBlock::LQR_Dead;
64426447
if (SCCNotDead) {
64436448
SaveSCCReg = MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
64446449
BuildMI(MBB, Begin, DL, TII.get(AMDGPU::S_CSELECT_B32), SaveSCCReg)
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -global-isel=0 -mtriple=amdgcn -mcpu=gfx1100 -verify-machineinstrs < %s | FileCheck -check-prefix=SDAG %s
3+
; RUN: llc -global-isel=1 -mtriple=amdgcn -mcpu=gfx1100 -verify-machineinstrs < %s | FileCheck -check-prefix=GISEL %s
4+
5+
; Check for verifier error due to trying to save and restore SCC
6+
; around a waterfall looop when it was never defined. We have to get
7+
; an accurate liveness at the use point and cannot rely on an
8+
; imprecise maybe-live query.
9+
10+
define void @issue92561(ptr addrspace(1) %arg) {
11+
; SDAG-LABEL: issue92561:
12+
; SDAG: ; %bb.0: ; %bb
13+
; SDAG-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
14+
; SDAG-NEXT: s_clause 0x1
15+
; SDAG-NEXT: global_load_b128 v[4:7], v[0:1], off offset:16
16+
; SDAG-NEXT: global_load_b128 v[0:3], v[0:1], off
17+
; SDAG-NEXT: v_mov_b32_e32 v8, 0
18+
; SDAG-NEXT: s_mov_b32 s12, 0
19+
; SDAG-NEXT: s_mov_b32 s3, exec_lo
20+
; SDAG-NEXT: s_mov_b32 s13, s12
21+
; SDAG-NEXT: s_mov_b32 s14, s12
22+
; SDAG-NEXT: s_mov_b32 s15, s12
23+
; SDAG-NEXT: s_waitcnt vmcnt(0)
24+
; SDAG-NEXT: .LBB0_1: ; =>This Inner Loop Header: Depth=1
25+
; SDAG-NEXT: v_readfirstlane_b32 s4, v0
26+
; SDAG-NEXT: v_readfirstlane_b32 s5, v1
27+
; SDAG-NEXT: v_readfirstlane_b32 s6, v2
28+
; SDAG-NEXT: v_readfirstlane_b32 s7, v3
29+
; SDAG-NEXT: v_readfirstlane_b32 s8, v4
30+
; SDAG-NEXT: v_readfirstlane_b32 s9, v5
31+
; SDAG-NEXT: v_readfirstlane_b32 s10, v6
32+
; SDAG-NEXT: v_readfirstlane_b32 s11, v7
33+
; SDAG-NEXT: v_cmp_eq_u64_e32 vcc_lo, s[4:5], v[0:1]
34+
; SDAG-NEXT: v_cmp_eq_u64_e64 s0, s[6:7], v[2:3]
35+
; SDAG-NEXT: v_cmp_eq_u64_e64 s1, s[8:9], v[4:5]
36+
; SDAG-NEXT: s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
37+
; SDAG-NEXT: v_cmp_eq_u64_e64 s2, s[10:11], v[6:7]
38+
; SDAG-NEXT: s_and_b32 s0, vcc_lo, s0
39+
; SDAG-NEXT: s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
40+
; SDAG-NEXT: s_and_b32 s0, s0, s1
41+
; SDAG-NEXT: s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
42+
; SDAG-NEXT: s_and_b32 s0, s0, s2
43+
; SDAG-NEXT: s_delay_alu instid0(SALU_CYCLE_1)
44+
; SDAG-NEXT: s_and_saveexec_b32 s0, s0
45+
; SDAG-NEXT: image_sample_c_lz v9, [v8, v8, v8, v8], s[4:11], s[12:15] dmask:0x1 dim:SQ_RSRC_IMG_2D_ARRAY
46+
; SDAG-NEXT: ; implicit-def: $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7
47+
; SDAG-NEXT: ; implicit-def: $vgpr8
48+
; SDAG-NEXT: s_xor_b32 exec_lo, exec_lo, s0
49+
; SDAG-NEXT: s_cbranch_execnz .LBB0_1
50+
; SDAG-NEXT: ; %bb.2:
51+
; SDAG-NEXT: s_mov_b32 exec_lo, s3
52+
; SDAG-NEXT: v_dual_mov_b32 v0, 0x7fc00000 :: v_dual_mov_b32 v1, 0
53+
; SDAG-NEXT: v_mov_b32_e32 v2, 1.0
54+
; SDAG-NEXT: s_mov_b32 s0, s12
55+
; SDAG-NEXT: s_mov_b32 s1, s12
56+
; SDAG-NEXT: s_mov_b32 s2, s12
57+
; SDAG-NEXT: s_mov_b32 s3, s12
58+
; SDAG-NEXT: s_mov_b32 s4, s12
59+
; SDAG-NEXT: s_mov_b32 s5, s12
60+
; SDAG-NEXT: s_mov_b32 s6, s12
61+
; SDAG-NEXT: s_mov_b32 s7, s12
62+
; SDAG-NEXT: s_clause 0x2
63+
; SDAG-NEXT: image_sample_c_lz v0, [v1, v1, v0, v1], s[0:7], s[12:15] dmask:0x1 dim:SQ_RSRC_IMG_2D_ARRAY
64+
; SDAG-NEXT: image_sample_c_lz v3, [v1, v1, v1, v1], s[0:7], s[12:15] dmask:0x1 dim:SQ_RSRC_IMG_2D_ARRAY
65+
; SDAG-NEXT: image_sample_c_lz v2, [v1, v2, v1, v1], s[0:7], s[12:15] dmask:0x1 dim:SQ_RSRC_IMG_2D_ARRAY
66+
; SDAG-NEXT: v_mov_b32_e32 v4, v1
67+
; SDAG-NEXT: s_waitcnt vmcnt(2)
68+
; SDAG-NEXT: v_add_f32_e32 v0, v9, v0
69+
; SDAG-NEXT: s_waitcnt vmcnt(0)
70+
; SDAG-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
71+
; SDAG-NEXT: v_add_f32_e32 v0, v2, v0
72+
; SDAG-NEXT: v_mov_b32_e32 v2, v1
73+
; SDAG-NEXT: v_dual_add_f32 v0, v3, v0 :: v_dual_mov_b32 v3, v1
74+
; SDAG-NEXT: s_delay_alu instid0(VALU_DEP_1)
75+
; SDAG-NEXT: v_mul_f32_e32 v0, 0x3e800000, v0
76+
; SDAG-NEXT: image_store v[0:2], v[3:4], s[0:7] dim:SQ_RSRC_IMG_2D unorm
77+
; SDAG-NEXT: s_setpc_b64 s[30:31]
78+
;
79+
; GISEL-LABEL: issue92561:
80+
; GISEL: ; %bb.0: ; %bb
81+
; GISEL-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
82+
; GISEL-NEXT: s_clause 0x1
83+
; GISEL-NEXT: global_load_b128 v[2:5], v[0:1], off
84+
; GISEL-NEXT: global_load_b128 v[6:9], v[0:1], off offset:16
85+
; GISEL-NEXT: v_mov_b32_e32 v0, 0
86+
; GISEL-NEXT: s_mov_b32 s20, 0
87+
; GISEL-NEXT: s_mov_b32 s3, exec_lo
88+
; GISEL-NEXT: s_mov_b32 s21, s20
89+
; GISEL-NEXT: s_mov_b32 s22, s20
90+
; GISEL-NEXT: s_mov_b32 s23, s20
91+
; GISEL-NEXT: s_mov_b32 s4, s20
92+
; GISEL-NEXT: s_mov_b32 s5, s20
93+
; GISEL-NEXT: s_mov_b32 s6, s20
94+
; GISEL-NEXT: s_mov_b32 s7, s20
95+
; GISEL-NEXT: s_mov_b32 s8, s20
96+
; GISEL-NEXT: s_mov_b32 s9, s20
97+
; GISEL-NEXT: s_mov_b32 s10, s20
98+
; GISEL-NEXT: s_mov_b32 s11, s20
99+
; GISEL-NEXT: s_waitcnt vmcnt(0)
100+
; GISEL-NEXT: .LBB0_1: ; =>This Inner Loop Header: Depth=1
101+
; GISEL-NEXT: v_readfirstlane_b32 s12, v2
102+
; GISEL-NEXT: v_readfirstlane_b32 s13, v3
103+
; GISEL-NEXT: v_readfirstlane_b32 s14, v4
104+
; GISEL-NEXT: v_readfirstlane_b32 s15, v5
105+
; GISEL-NEXT: v_readfirstlane_b32 s16, v6
106+
; GISEL-NEXT: v_readfirstlane_b32 s17, v7
107+
; GISEL-NEXT: v_readfirstlane_b32 s18, v8
108+
; GISEL-NEXT: v_readfirstlane_b32 s19, v9
109+
; GISEL-NEXT: v_cmp_eq_u64_e32 vcc_lo, s[12:13], v[2:3]
110+
; GISEL-NEXT: v_cmp_eq_u64_e64 s0, s[14:15], v[4:5]
111+
; GISEL-NEXT: v_cmp_eq_u64_e64 s1, s[16:17], v[6:7]
112+
; GISEL-NEXT: s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
113+
; GISEL-NEXT: v_cmp_eq_u64_e64 s2, s[18:19], v[8:9]
114+
; GISEL-NEXT: s_and_b32 s0, vcc_lo, s0
115+
; GISEL-NEXT: s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
116+
; GISEL-NEXT: s_and_b32 s0, s0, s1
117+
; GISEL-NEXT: s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
118+
; GISEL-NEXT: s_and_b32 s0, s0, s2
119+
; GISEL-NEXT: s_delay_alu instid0(SALU_CYCLE_1)
120+
; GISEL-NEXT: s_and_saveexec_b32 s0, s0
121+
; GISEL-NEXT: image_sample_c_lz v1, [v0, v0, v0, v0], s[12:19], s[20:23] dmask:0x1 dim:SQ_RSRC_IMG_2D_ARRAY
122+
; GISEL-NEXT: ; implicit-def: $vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9
123+
; GISEL-NEXT: ; implicit-def: $vgpr0
124+
; GISEL-NEXT: s_xor_b32 exec_lo, exec_lo, s0
125+
; GISEL-NEXT: s_cbranch_execnz .LBB0_1
126+
; GISEL-NEXT: ; %bb.2:
127+
; GISEL-NEXT: s_mov_b32 exec_lo, s3
128+
; GISEL-NEXT: v_dual_mov_b32 v2, 0 :: v_dual_mov_b32 v3, 1.0
129+
; GISEL-NEXT: v_mov_b32_e32 v0, 0x7fc00000
130+
; GISEL-NEXT: s_clause 0x2
131+
; GISEL-NEXT: image_sample_c_lz v0, [v2, v2, v0, v2], s[4:11], s[20:23] dmask:0x1 dim:SQ_RSRC_IMG_2D_ARRAY
132+
; GISEL-NEXT: image_sample_c_lz v3, [v2, v3, v2, v2], s[4:11], s[20:23] dmask:0x1 dim:SQ_RSRC_IMG_2D_ARRAY
133+
; GISEL-NEXT: image_sample_c_lz v4, [v2, v2, v2, v2], s[4:11], s[20:23] dmask:0x1 dim:SQ_RSRC_IMG_2D_ARRAY
134+
; GISEL-NEXT: s_mov_b32 s21, s20
135+
; GISEL-NEXT: s_waitcnt vmcnt(2)
136+
; GISEL-NEXT: v_add_f32_e32 v0, v1, v0
137+
; GISEL-NEXT: s_waitcnt vmcnt(1)
138+
; GISEL-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
139+
; GISEL-NEXT: v_dual_add_f32 v0, v3, v0 :: v_dual_mov_b32 v3, v2
140+
; GISEL-NEXT: s_waitcnt vmcnt(0)
141+
; GISEL-NEXT: v_add_f32_e32 v0, v4, v0
142+
; GISEL-NEXT: v_dual_mov_b32 v4, s20 :: v_dual_mov_b32 v5, s21
143+
; GISEL-NEXT: s_delay_alu instid0(VALU_DEP_2)
144+
; GISEL-NEXT: v_mul_f32_e32 v1, 0x3e800000, v0
145+
; GISEL-NEXT: image_store v[1:3], v[4:5], s[4:11] dim:SQ_RSRC_IMG_2D unorm
146+
; GISEL-NEXT: s_setpc_b64 s[30:31]
147+
bb:
148+
%descriptor = load <8 x i32>, ptr addrspace(1) %arg, align 32
149+
%needs.waterfall = call float @llvm.amdgcn.image.sample.c.lz.2darray.f32.f32(i32 1, float 0.0, float 0.0, float 0.0, float 0.0, <8 x i32> %descriptor, <4 x i32> zeroinitializer, i1 false, i32 0, i32 0)
150+
%i2 = call float @llvm.amdgcn.image.sample.c.lz.2darray.f32.f32(i32 1, float 0.0, float 0.0, float 0x7FF8000000000000, float 0.0, <8 x i32> zeroinitializer, <4 x i32> zeroinitializer, i1 false, i32 0, i32 0)
151+
%i3 = fadd float %needs.waterfall, %i2
152+
%i4 = call float @llvm.amdgcn.image.sample.c.lz.2darray.f32.f32(i32 1, float 0.0, float 1.000000e+00, float 0.0, float 0.0, <8 x i32> zeroinitializer, <4 x i32> zeroinitializer, i1 false, i32 0, i32 0)
153+
%i5 = fadd float %i4, %i3
154+
%i6 = call float @llvm.amdgcn.image.sample.c.lz.2darray.f32.f32(i32 1, float 0.0, float 0.0, float 0.0, float 0.0, <8 x i32> zeroinitializer, <4 x i32> zeroinitializer, i1 false, i32 0, i32 0)
155+
%i7 = fadd float %i6, %i5
156+
%i8 = fmul float %i7, 2.500000e-01
157+
%i9 = insertelement <3 x float> zeroinitializer, float %i8, i64 0
158+
call void @llvm.amdgcn.image.store.2d.v3f32.i32(<3 x float> %i9, i32 0, i32 0, i32 0, <8 x i32> zeroinitializer, i32 0, i32 0)
159+
ret void
160+
}

0 commit comments

Comments
 (0)