diff --git a/llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp b/llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp --- a/llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp +++ b/llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp @@ -162,12 +162,15 @@ << *And); Register CCReg = CC->getReg(); + bool AndSCCIsDead = !!And->findRegisterDefOperand(AMDGPU::SCC, true); LIS->RemoveMachineInstrFromMaps(*And); MachineInstr *Andn2 = BuildMI(MBB, *And, And->getDebugLoc(), TII->get(Andn2Opc), And->getOperand(0).getReg()) .addReg(ExecReg) .addReg(CCReg, getUndefRegState(CC->isUndef()), CC->getSubReg()); + if (MachineOperand *Andn2SCC = Andn2->findRegisterDefOperand(AMDGPU::SCC)) + Andn2SCC->setIsDead(AndSCCIsDead); And->eraseFromParent(); LIS->InsertMachineInstrInMaps(*Andn2); diff --git a/llvm/test/CodeGen/AMDGPU/optimize-exec-masking-pre-ra.mir b/llvm/test/CodeGen/AMDGPU/optimize-exec-masking-pre-ra.mir --- a/llvm/test/CodeGen/AMDGPU/optimize-exec-masking-pre-ra.mir +++ b/llvm/test/CodeGen/AMDGPU/optimize-exec-masking-pre-ra.mir @@ -104,7 +104,7 @@ ; GCN-LABEL: name: cndmask_cmp_cbranch_fold_undef ; GCN: bb.0: ; GCN: successors: %bb.1(0x80000000) - ; GCN: $vcc = S_ANDN2_B64 $exec, undef %1:sreg_64_xexec, implicit-def $scc + ; GCN: $vcc = S_ANDN2_B64 $exec, undef %1:sreg_64_xexec, implicit-def dead $scc ; GCN: S_CBRANCH_VCCZ %bb.1, implicit $vcc ; GCN: bb.1: bb.0: diff --git a/llvm/test/CodeGen/AMDGPU/optimize-negated-cond-exec-masking-wave32.mir b/llvm/test/CodeGen/AMDGPU/optimize-negated-cond-exec-masking-wave32.mir --- a/llvm/test/CodeGen/AMDGPU/optimize-negated-cond-exec-masking-wave32.mir +++ b/llvm/test/CodeGen/AMDGPU/optimize-negated-cond-exec-masking-wave32.mir @@ -2,7 +2,7 @@ # GCN: name: negated_cond_vop2 # GCN: %0:sgpr_32 = IMPLICIT_DEF -# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def $scc +# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop2 @@ -24,7 +24,7 @@ # GCN: name: negated_cond_vop3 # GCN: %0:sgpr_32 = IMPLICIT_DEF -# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def $scc +# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop3 @@ -116,7 +116,7 @@ # GCN: name: negated_cond_vop3_imp_vcc # GCN: $vcc_lo = IMPLICIT_DEF -# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, $vcc_lo, implicit-def $scc +# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, $vcc_lo, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop3_imp_vcc @@ -138,7 +138,7 @@ # GCN: name: negated_cond_vop2_imp_vcc # GCN: $vcc_lo = IMPLICIT_DEF -# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, $vcc_lo, implicit-def $scc +# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, $vcc_lo, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop2_imp_vcc @@ -187,7 +187,7 @@ # GCN: name: negated_cond_vop2_used_sel # GCN: %0:sgpr_32 = IMPLICIT_DEF # GCN-NEXT: %1:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, 1, %0, implicit $exec -# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def $scc +# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop2_used_sel @@ -213,7 +213,7 @@ # GCN-NEXT: %1:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, 1, %0, implicit $exec # GCN-NEXT: V_CMP_NE_U32_e32 1, %1, implicit-def $vcc, implicit $exec # GCN-NEXT: $sgpr0_sgpr1 = COPY $vcc -# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def $scc +# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop2_used_vcc @@ -289,7 +289,7 @@ # GCN: name: negated_cond_vop3_sel_right_subreg1 # GCN: %0:sgpr_32 = IMPLICIT_DEF # GCN-NEXT: %1.sub1:vreg_64 = IMPLICIT_DEF -# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def $scc +# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop3_sel_right_subreg1 @@ -313,7 +313,7 @@ # GCN: name: negated_cond_vop3_sel_right_subreg2 # GCN: %0:sgpr_32 = IMPLICIT_DEF # GCN-NEXT: %1.sub1:vreg_64 = IMPLICIT_DEF -# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def $scc +# GCN-NEXT: $vcc_lo = S_ANDN2_B32 $exec_lo, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop3_sel_right_subreg2 diff --git a/llvm/test/CodeGen/AMDGPU/optimize-negated-cond-exec-masking.mir b/llvm/test/CodeGen/AMDGPU/optimize-negated-cond-exec-masking.mir --- a/llvm/test/CodeGen/AMDGPU/optimize-negated-cond-exec-masking.mir +++ b/llvm/test/CodeGen/AMDGPU/optimize-negated-cond-exec-masking.mir @@ -2,7 +2,7 @@ # GCN: name: negated_cond_vop2 # GCN: %0:sreg_64_xexec = IMPLICIT_DEF -# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc +# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop2 @@ -24,7 +24,7 @@ # GCN: name: negated_cond_vop3 # GCN: %0:sreg_64_xexec = IMPLICIT_DEF -# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc +# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop3 @@ -142,7 +142,7 @@ # GCN: name: negated_cond_vop3_imp_vcc # GCN: $vcc = IMPLICIT_DEF -# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, $vcc, implicit-def $scc +# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, $vcc, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop3_imp_vcc @@ -164,7 +164,7 @@ # GCN: name: negated_cond_vop2_imp_vcc # GCN: $vcc = IMPLICIT_DEF -# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, $vcc, implicit-def $scc +# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, $vcc, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop2_imp_vcc @@ -213,7 +213,7 @@ # GCN: name: negated_cond_vop2_used_sel # GCN: %0:sreg_64_xexec = IMPLICIT_DEF # GCN-NEXT: %1:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, 1, %0, implicit $exec -# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc +# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop2_used_sel @@ -239,7 +239,7 @@ # GCN-NEXT: %1:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, 1, %0, implicit $exec # GCN-NEXT: V_CMP_NE_U32_e32 1, %1, implicit-def $vcc, implicit $exec # GCN-NEXT: $sgpr0_sgpr1 = COPY $vcc -# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc +# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop2_used_vcc @@ -315,7 +315,7 @@ # GCN: name: negated_cond_vop3_sel_right_subreg1 # GCN: %0:sreg_64_xexec = IMPLICIT_DEF # GCN-NEXT: %1.sub1:vreg_64 = IMPLICIT_DEF -# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc +# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop3_sel_right_subreg1 @@ -339,7 +339,7 @@ # GCN: name: negated_cond_vop3_sel_right_subreg2 # GCN: %0:sreg_64_xexec = IMPLICIT_DEF # GCN-NEXT: %1.sub1:vreg_64 = IMPLICIT_DEF -# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc +# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_vop3_sel_right_subreg2 @@ -388,7 +388,7 @@ # GCN: name: negated_cond_vop2_dominated_blocks # GCN: %0:sreg_64_xexec = IMPLICIT_DEF -# GCN: $vcc = S_ANDN2_B64 $exec, %0, implicit-def $scc +# GCN: $vcc = S_ANDN2_B64 $exec, %0, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.3, implicit $vcc --- name: negated_cond_vop2_dominated_blocks @@ -466,7 +466,7 @@ # GCN: name: negated_cond_subreg # GCN: %0.sub0_sub1:sgpr_128 = IMPLICIT_DEF -# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0.sub0_sub1, implicit-def $scc +# GCN-NEXT: $vcc = S_ANDN2_B64 $exec, %0.sub0_sub1, implicit-def dead $scc # GCN-NEXT: S_CBRANCH_VCCNZ %bb.2, implicit $vcc --- name: negated_cond_subreg