diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp --- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp +++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp @@ -1528,6 +1528,13 @@ return StrictDom; } +static bool isWaitInstr(MachineInstr &Inst) { + return Inst.getOpcode() == AMDGPU::S_WAITCNT || + (Inst.getOpcode() == AMDGPU::S_WAITCNT_VSCNT && + Inst.getOperand(0).isReg() && + Inst.getOperand(0).getReg() == AMDGPU::SGPR_NULL); +} + // Generate s_waitcnt instructions where needed. bool SIInsertWaitcnts::insertWaitcntInBlock(MachineFunction &MF, MachineBasicBlock &Block, @@ -1563,10 +1570,7 @@ // Track pre-existing waitcnts that were added in earlier iterations or by // the memory legalizer. - if (Inst.getOpcode() == AMDGPU::S_WAITCNT || - (Inst.getOpcode() == AMDGPU::S_WAITCNT_VSCNT && - Inst.getOperand(0).isReg() && - Inst.getOperand(0).getReg() == AMDGPU::SGPR_NULL)) { + if (isWaitInstr(Inst)) { if (!OldWaitcntInstr) OldWaitcntInstr = &Inst; ++Iter;