Index: llvm/lib/Target/AMDGPU/GCNRegPressure.cpp =================================================================== --- llvm/lib/Target/AMDGPU/GCNRegPressure.cpp +++ llvm/lib/Target/AMDGPU/GCNRegPressure.cpp @@ -384,6 +384,7 @@ void GCNDownwardRPTracker::advanceToNext() { LastTrackedMI = &*NextMI++; + NextMI = skipDebugInstructionsForward(NextMI, MBBEnd); // Add new registers or mask bits. for (const auto &MO : LastTrackedMI->operands()) { Index: llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp =================================================================== --- llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp +++ llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp @@ -106,7 +106,8 @@ // There no sense to create store clauses, they do not define anything, // thus there is nothing to set early-clobber. static bool isValidClauseInst(const MachineInstr &MI, bool IsVMEMClause) { - if (MI.isDebugValue() || MI.isBundled()) + assert(!MI.isDebugInstr() && "debug instructions should not reach here"); + if (MI.isBundled()) return false; if (!MI.mayLoad() || MI.mayStore()) return false; @@ -321,6 +322,8 @@ unsigned FuncMaxClause = AMDGPU::getIntegerAttribute( MF.getFunction(), "amdgpu-max-memory-clause", MaxClause); + SmallVector DbgInstrs; + for (MachineBasicBlock &MBB : MF) { GCNDownwardRPTracker RPT(*LIS); MachineBasicBlock::instr_iterator Next; @@ -328,6 +331,9 @@ MachineInstr &MI = *I; Next = std::next(I); + if (MI.isDebugInstr()) + continue; + bool IsVMEM = isVMEMClauseInst(MI); if (!isValidClauseInst(MI, IsVMEM)) @@ -349,6 +355,13 @@ unsigned Length = 1; for ( ; Next != E && Length < FuncMaxClause; ++Next) { + // Debug instructions should not change the bundling. We need to move + // these after the bundle + if (Next->isDebugInstr()) { + //DbgInstrs.push_back(&*Next); + continue; + } + if (!isValidClauseInst(*Next, IsVMEM)) break; @@ -373,8 +386,17 @@ // Restore the state after processing the bundle. RPT.reset(*B, &LiveRegsCopy); + DbgInstrs.clear(); + + auto BundleNext = I; + for (auto BI = I; BI != Next; BI = BundleNext) { + BundleNext = std::next(BI); + + if (BI->isDebugValue()) { + DbgInstrs.push_back(BI->removeFromParent()); + continue; + } - for (auto BI = I; BI != Next; ++BI) { BI->bundleWithPred(); Ind->removeSingleMachineInstrFromMaps(*BI); @@ -383,6 +405,10 @@ MO.setIsInternalRead(true); } + // Replace any debug instructions after the new bundle. + for (MachineInstr *DbgInst : DbgInstrs) + MBB.insert(BundleNext, DbgInst); + for (auto &&R : Defs) { forAllLanes(R.first, R.second.second, [&R, &B](unsigned SubReg) { unsigned S = R.second.first | RegState::EarlyClobber;