Index: llvm/include/llvm/CodeGen/MachineBasicBlock.h =================================================================== --- llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -246,6 +246,7 @@ MachineInstrBundleIterator; unsigned size() const { return (unsigned)Insts.size(); } + unsigned sizeWithoutDebug() const; bool empty() const { return Insts.empty(); } MachineInstr &instr_front() { return Insts.front(); } Index: llvm/lib/CodeGen/MachineBasicBlock.cpp =================================================================== --- llvm/lib/CodeGen/MachineBasicBlock.cpp +++ llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -1617,6 +1617,11 @@ return liveout_iterator(*this, ExceptionPointer, ExceptionSelector, false); } +unsigned MachineBasicBlock::sizeWithoutDebug() const { + auto R = instructionsWithoutDebug(begin(), end()); + return std::distance(R.begin(), R.end()); +} + const MBBSectionID MBBSectionID::ColdSectionID(MBBSectionID::SectionType::Cold); const MBBSectionID MBBSectionID::ExceptionSectionID(MBBSectionID::SectionType::Exception); Index: llvm/lib/CodeGen/MachineSink.cpp =================================================================== --- llvm/lib/CodeGen/MachineSink.cpp +++ llvm/lib/CodeGen/MachineSink.cpp @@ -1175,7 +1175,7 @@ // If this BB is too big or the block number in straight line between From // and To is too big, stop searching to save compiling time. - if (BB->size() > SinkLoadInstsPerBlockThreshold || + if (BB->sizeWithoutDebug() > SinkLoadInstsPerBlockThreshold || HandledDomBlocks.size() > SinkLoadBlocksThreshold) { for (auto *DomBB : HandledDomBlocks) { if (DomBB != BB && DT->dominates(DomBB, BB)) @@ -1277,7 +1277,7 @@ dbgs() << "CycleSink: Not sinking, sink block is the preheader\n"); return false; } - if (SinkBlock->size() > SinkLoadInstsPerBlockThreshold) { + if (SinkBlock->sizeWithoutDebug() > SinkLoadInstsPerBlockThreshold) { LLVM_DEBUG( dbgs() << "CycleSink: Not Sinking, block too large to analyse.\n"); return false;