Skip to content

Commit 74c1420

Browse files
committed
[AMDGPU] Propagate dead flag during pre-RA exec mask optimizations
Preserve SCC dead flags in SIOptimizeExecMaskingPreRA. This helps with removing redundant s_andn2 instructions later. Reviewed By: rampitec Differential Revision: https://reviews.llvm.org/D83637
1 parent 62f5ba6 commit 74c1420

4 files changed

Lines changed: 24 additions & 19 deletions

File tree

‎llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ static unsigned optimizeVcndVcmpPair(MachineBasicBlock &MBB,
168168
And->getOperand(0).getReg())
169169
.addReg(ExecReg)
170170
.addReg(CCReg, getUndefRegState(CC->isUndef()), CC->getSubReg());
171+
MachineOperand &AndSCC = And->getOperand(3);
172+
assert(AndSCC.getReg() == AMDGPU::SCC);
173+
MachineOperand &Andn2SCC = Andn2->getOperand(3);
174+
assert(Andn2SCC.getReg() == AMDGPU::SCC);
175+
Andn2SCC.setIsDead(AndSCC.isDead());
171176
And->eraseFromParent();
172177
LIS->InsertMachineInstrInMaps(*Andn2);
173178

‎llvm/test/CodeGen/AMDGPU/optimize-exec-masking-pre-ra.mir‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ body: |
104104
; GCN-LABEL: name: cndmask_cmp_cbranch_fold_undef
105105
; GCN: bb.0:
106106
; GCN: successors: %bb.1(0x80000000)
107-
; GCN: $vcc = S_ANDN2_B64 $exec, undef %1:sreg_64_xexec, implicit-def $scc
107+
; GCN: $vcc = S_ANDN2_B64 $exec, undef %1:sreg_64_xexec, implicit-def dead $scc
108108
; GCN: S_CBRANCH_VCCZ %bb.1, implicit $vcc
109109
; GCN: bb.1:
110110
bb.0:

‎llvm/test/CodeGen/AMDGPU/optimize-negated-cond-exec-masking-wave32.mir‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# GCN: name: negated_cond_vop2
44
# GCN: %0:sgpr_32 = IMPLICIT_DEF
5-
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def $scc
5+
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def dead $scc
66
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
77
---
88
name: negated_cond_vop2
@@ -24,7 +24,7 @@ body: |
2424

2525
# GCN: name: negated_cond_vop3
2626
# GCN: %0:sgpr_32 = IMPLICIT_DEF
27-
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def $scc
27+
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def dead $scc
2828
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
2929
---
3030
name: negated_cond_vop3
@@ -116,7 +116,7 @@ body: |
116116

117117
# GCN: name: negated_cond_vop3_imp_vcc
118118
# GCN: $vcc_lo = IMPLICIT_DEF
119-
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, $vcc_lo, implicit-def $scc
119+
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, $vcc_lo, implicit-def dead $scc
120120
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
121121
---
122122
name: negated_cond_vop3_imp_vcc
@@ -138,7 +138,7 @@ body: |
138138

139139
# GCN: name: negated_cond_vop2_imp_vcc
140140
# GCN: $vcc_lo = IMPLICIT_DEF
141-
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, $vcc_lo, implicit-def $scc
141+
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, $vcc_lo, implicit-def dead $scc
142142
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
143143
---
144144
name: negated_cond_vop2_imp_vcc
@@ -187,7 +187,7 @@ body: |
187187
# GCN: name: negated_cond_vop2_used_sel
188188
# GCN: %0:sgpr_32 = IMPLICIT_DEF
189189
# GCN-NEXT: %1:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, 1, %0, implicit $exec
190-
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def $scc
190+
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def dead $scc
191191
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
192192
---
193193
name: negated_cond_vop2_used_sel
@@ -213,7 +213,7 @@ body: |
213213
# GCN-NEXT: %1:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, 1, %0, implicit $exec
214214
# GCN-NEXT: V_CMP_NE_U32_e32 1, %1, implicit-def $vcc, implicit $exec
215215
# GCN-NEXT: $sgpr0_sgpr1 = COPY $vcc
216-
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def $scc
216+
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def dead $scc
217217
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
218218
---
219219
name: negated_cond_vop2_used_vcc
@@ -289,7 +289,7 @@ body: |
289289
# GCN: name: negated_cond_vop3_sel_right_subreg1
290290
# GCN: %0:sgpr_32 = IMPLICIT_DEF
291291
# GCN-NEXT: %1.sub1:vreg_64 = IMPLICIT_DEF
292-
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def $scc
292+
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def dead $scc
293293
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
294294
---
295295
name: negated_cond_vop3_sel_right_subreg1
@@ -313,7 +313,7 @@ body: |
313313
# GCN: name: negated_cond_vop3_sel_right_subreg2
314314
# GCN: %0:sgpr_32 = IMPLICIT_DEF
315315
# GCN-NEXT: %1.sub1:vreg_64 = IMPLICIT_DEF
316-
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def $scc
316+
# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def dead $scc
317317
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
318318
---
319319
name: negated_cond_vop3_sel_right_subreg2

‎llvm/test/CodeGen/AMDGPU/optimize-negated-cond-exec-masking.mir‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# GCN: name: negated_cond_vop2
44
# GCN: %0:sreg_64_xexec = IMPLICIT_DEF
5-
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc
5+
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc
66
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
77
---
88
name: negated_cond_vop2
@@ -24,7 +24,7 @@ body: |
2424

2525
# GCN: name: negated_cond_vop3
2626
# GCN: %0:sreg_64_xexec = IMPLICIT_DEF
27-
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc
27+
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc
2828
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
2929
---
3030
name: negated_cond_vop3
@@ -142,7 +142,7 @@ body: |
142142

143143
# GCN: name: negated_cond_vop3_imp_vcc
144144
# GCN: $vcc = IMPLICIT_DEF
145-
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, $vcc, implicit-def $scc
145+
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, $vcc, implicit-def dead $scc
146146
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
147147
---
148148
name: negated_cond_vop3_imp_vcc
@@ -164,7 +164,7 @@ body: |
164164

165165
# GCN: name: negated_cond_vop2_imp_vcc
166166
# GCN: $vcc = IMPLICIT_DEF
167-
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, $vcc, implicit-def $scc
167+
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, $vcc, implicit-def dead $scc
168168
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
169169
---
170170
name: negated_cond_vop2_imp_vcc
@@ -213,7 +213,7 @@ body: |
213213
# GCN: name: negated_cond_vop2_used_sel
214214
# GCN: %0:sreg_64_xexec = IMPLICIT_DEF
215215
# GCN-NEXT: %1:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, 1, %0, implicit $exec
216-
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc
216+
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc
217217
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
218218
---
219219
name: negated_cond_vop2_used_sel
@@ -239,7 +239,7 @@ body: |
239239
# GCN-NEXT: %1:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, 1, %0, implicit $exec
240240
# GCN-NEXT: V_CMP_NE_U32_e32 1, %1, implicit-def $vcc, implicit $exec
241241
# GCN-NEXT: $sgpr0_sgpr1 = COPY $vcc
242-
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc
242+
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc
243243
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
244244
---
245245
name: negated_cond_vop2_used_vcc
@@ -315,7 +315,7 @@ body: |
315315
# GCN: name: negated_cond_vop3_sel_right_subreg1
316316
# GCN: %0:sreg_64_xexec = IMPLICIT_DEF
317317
# GCN-NEXT: %1.sub1:vreg_64 = IMPLICIT_DEF
318-
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc
318+
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc
319319
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
320320
---
321321
name: negated_cond_vop3_sel_right_subreg1
@@ -339,7 +339,7 @@ body: |
339339
# GCN: name: negated_cond_vop3_sel_right_subreg2
340340
# GCN: %0:sreg_64_xexec = IMPLICIT_DEF
341341
# GCN-NEXT: %1.sub1:vreg_64 = IMPLICIT_DEF
342-
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc
342+
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc
343343
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
344344
---
345345
name: negated_cond_vop3_sel_right_subreg2
@@ -388,7 +388,7 @@ body: |
388388

389389
# GCN: name: negated_cond_vop2_dominated_blocks
390390
# GCN: %0:sreg_64_xexec = IMPLICIT_DEF
391-
# GCN: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc
391+
# GCN: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc
392392
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.3, implicit $vcc
393393
---
394394
name: negated_cond_vop2_dominated_blocks
@@ -466,7 +466,7 @@ body: |
466466

467467
# GCN: name: negated_cond_subreg
468468
# GCN: %0.sub0_sub1:sgpr_128 = IMPLICIT_DEF
469-
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0.sub0_sub1, implicit-def $scc
469+
# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0.sub0_sub1, implicit-def dead $scc
470470
# GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc
471471
---
472472
name: negated_cond_subreg

0 commit comments

Comments
 (0)