Index: lib/Target/AMDGPU/GCNIterativeScheduler.cpp =================================================================== --- lib/Target/AMDGPU/GCNIterativeScheduler.cpp +++ lib/Target/AMDGPU/GCNIterativeScheduler.cpp @@ -236,6 +236,9 @@ UPTracker.recede(*I); UPTracker.recede(*Begin); + // Second recede to the same instruction to commit all defs. + // Current pressure will be updated, but max will stay higher. + UPTracker.recede(*Begin); assert(UPTracker.isValid() || (dbgs() << "Tracked region ", Index: lib/Target/AMDGPU/GCNRegPressure.cpp =================================================================== --- lib/Target/AMDGPU/GCNRegPressure.cpp +++ lib/Target/AMDGPU/GCNRegPressure.cpp @@ -262,29 +262,31 @@ void GCNUpwardRPTracker::recede(const MachineInstr &MI) { assert(MRI && "call reset first"); + // process all defs first to ensure early clobbers are handled correctly + // iterating over operands() to catch implicit defs + if (LastTrackedMI && !LastTrackedMI->isDebugValue()) { + for (const auto &MO : LastTrackedMI->operands()) { + if (!MO.isReg() || !MO.isDef() || MO.isTied() || + !TargetRegisterInfo::isVirtualRegister(MO.getReg())) + continue; + + auto Reg = MO.getReg(); + auto &LiveMask = LiveRegs[Reg]; + auto PrevMask = LiveMask; + LiveMask &= ~getDefRegMask(MO); + CurPressure.inc(Reg, PrevMask, LiveMask, *MRI); + } + } + LastTrackedMI = &MI; if (MI.isDebugValue()) return; - // process all defs first to ensure early clobbers are handled correctly - // iterating over operands() to catch implicit defs - for (const auto &MO : MI.operands()) { - if (!MO.isReg() || !MO.isDef() || - !TargetRegisterInfo::isVirtualRegister(MO.getReg())) - continue; - - auto Reg = MO.getReg(); - auto &LiveMask = LiveRegs[Reg]; - auto PrevMask = LiveMask; - LiveMask &= ~getDefRegMask(MO); - CurPressure.inc(Reg, PrevMask, LiveMask, *MRI); - } - // then all uses for (const auto &MO : MI.uses()) { if (!MO.isReg() || !MO.readsReg() || - !TargetRegisterInfo::isVirtualRegister(MO.getReg())) + !TargetRegisterInfo::isVirtualRegister(MO.getReg())) continue; auto Reg = MO.getReg();