Index: include/llvm/CodeGen/MachineBasicBlock.h =================================================================== --- include/llvm/CodeGen/MachineBasicBlock.h +++ include/llvm/CodeGen/MachineBasicBlock.h @@ -814,10 +814,10 @@ /// MachineBasicBlock::{iterator, const_iterator, instr_iterator, /// const_instr_iterator} and the respective reverse iterators. template -inline IterT skipDebugInstructionsForward(IterT It, IterT End) { +inline bool skipDebugInstructionsForward(IterT &It, IterT End) { while (It != End && It->isDebugValue()) It++; - return It; + return It == End; } /// Decrement \p It until it points to a non-debug instruction or to \p Begin @@ -825,10 +825,10 @@ /// MachineBasicBlock::{iterator, const_iterator, instr_iterator, /// const_instr_iterator} and the respective reverse iterators. template -inline IterT skipDebugInstructionsBackward(IterT It, IterT Begin) { +inline bool skipDebugInstructionsBackward(IterT &It, IterT Begin) { while (It != Begin && It->isDebugValue()) It--; - return It; + return It == Begin; } } // End llvm namespace Index: lib/CodeGen/BranchFolding.cpp =================================================================== --- lib/CodeGen/BranchFolding.cpp +++ lib/CodeGen/BranchFolding.cpp @@ -1713,8 +1713,8 @@ // The terminator is probably a conditional branch, try not to separate the // branch from condition setting instruction. - MachineBasicBlock::iterator PI = - skipDebugInstructionsBackward(std::prev(Loc), MBB->begin()); + MachineBasicBlock::iterator PI = std::prev(Loc); + skipDebugInstructionsBackward(PI, MBB->begin()); bool IsDef = false; for (const MachineOperand &MO : PI->operands()) { @@ -1808,8 +1808,8 @@ MachineBasicBlock::iterator FIE = FBB->end(); while (TIB != TIE && FIB != FIE) { // Skip dbg_value instructions. These do not count. - TIB = skipDebugInstructionsForward(TIB, TIE); - FIB = skipDebugInstructionsForward(FIB, FIE); + skipDebugInstructionsForward(TIB, TIE); + skipDebugInstructionsForward(FIB, FIE); if (TIB == TIE || FIB == FIE) break; Index: lib/CodeGen/IfConversion.cpp =================================================================== --- lib/CodeGen/IfConversion.cpp +++ lib/CodeGen/IfConversion.cpp @@ -619,11 +619,9 @@ while (TIB != TIE && FIB != FIE) { // Skip dbg_value instructions. These do not count. - TIB = skipDebugInstructionsForward(TIB, TIE); - if (TIB == TIE) + if(skipDebugInstructionsForward(TIB, TIE)) break; - FIB = skipDebugInstructionsForward(FIB, FIE); - if (FIB == FIE) + if(skipDebugInstructionsForward(FIB, FIE)) break; if (!TIB->isIdenticalTo(*FIB)) break; @@ -663,11 +661,9 @@ while (RTIE != RTIB && RFIE != RFIB) { // Skip dbg_value instructions. These do not count. // Note that these are reverse iterators going forward. - RTIE = skipDebugInstructionsForward(RTIE, RTIB); - if (RTIE == RTIB) + if (skipDebugInstructionsForward(RTIE, RTIB)) break; - RFIE = skipDebugInstructionsForward(RFIE, RFIB); - if (RFIE == RFIB) + if (skipDebugInstructionsForward(RFIE, RFIB)) break; if (!RTIE->isIdenticalTo(*RFIE)) break; Index: lib/CodeGen/MachineBasicBlock.cpp =================================================================== --- lib/CodeGen/MachineBasicBlock.cpp +++ lib/CodeGen/MachineBasicBlock.cpp @@ -191,7 +191,9 @@ MachineBasicBlock::iterator MachineBasicBlock::getFirstNonDebugInstr() { // Skip over begin-of-block dbg_value instructions. - return skipDebugInstructionsForward(begin(), end()); + iterator I = begin(); + skipDebugInstructionsForward(I, end()); + return I; } MachineBasicBlock::iterator MachineBasicBlock::getLastNonDebugInstr() { @@ -1138,10 +1140,9 @@ DebugLoc MachineBasicBlock::findDebugLoc(instr_iterator MBBI) { // Skip debug declarations, we don't want a DebugLoc from them. - MBBI = skipDebugInstructionsForward(MBBI, instr_end()); - if (MBBI != instr_end()) - return MBBI->getDebugLoc(); - return {}; + if (skipDebugInstructionsForward(MBBI, instr_end())) + return {}; + return MBBI->getDebugLoc(); } /// Return probability of the edge from this block to MBB. Index: lib/CodeGen/MachineCSE.cpp =================================================================== --- lib/CodeGen/MachineCSE.cpp +++ lib/CodeGen/MachineCSE.cpp @@ -177,7 +177,7 @@ unsigned LookAheadLeft = LookAheadLimit; while (LookAheadLeft) { // Skip over dbg_value's. - I = skipDebugInstructionsForward(I, E); + skipDebugInstructionsForward(I, E); if (I == E) // Reached end of block, register is obviously dead. Index: lib/CodeGen/RegisterPressure.cpp =================================================================== --- lib/CodeGen/RegisterPressure.cpp +++ lib/CodeGen/RegisterPressure.cpp @@ -266,9 +266,8 @@ SlotIndex RegPressureTracker::getCurrSlot() const { - MachineBasicBlock::const_iterator IdxPos = - skipDebugInstructionsForward(CurrPos, MBB->end()); - if (IdxPos == MBB->end()) + auto IdxPos = CurrPos; + if(skipDebugInstructionsForward(IdxPos, MBB->end())) return LIS->getMBBEndIdx(MBB); return LIS->getInstructionIndex(*IdxPos).getRegSlot(); } @@ -816,7 +815,7 @@ static_cast(P).openTop(CurrPos); // Find the previous instruction. - CurrPos = skipDebugInstructionsBackward(std::prev(CurrPos), MBB->begin()); + skipDebugInstructionsBackward(--CurrPos, MBB->begin()); SlotIndex SlotIdx; if (RequireIntervals) @@ -892,7 +891,7 @@ bumpDeadDefs(RegOpers.DeadDefs); // Find the next instruction. - CurrPos = skipDebugInstructionsForward(std::next(CurrPos), MBB->end()); + skipDebugInstructionsForward(++CurrPos, MBB->end()); } void RegPressureTracker::advance() {