Index: llvm/lib/CodeGen/MachineSink.cpp =================================================================== --- llvm/lib/CodeGen/MachineSink.cpp +++ llvm/lib/CodeGen/MachineSink.cpp @@ -268,6 +268,16 @@ INITIALIZE_PASS_END(MachineSinking, DEBUG_TYPE, "Machine code sinking", false, false) +static unsigned sizeNoDbg(const MachineBasicBlock &MBB) { + unsigned Size = 0; + for (auto &MI : MBB) { + if (MI.isDebugInstr()) + continue; + Size++; + } + return Size; +} + bool MachineSinking::PerformTrivialForwardCoalescing(MachineInstr &MI, MachineBasicBlock *MBB) { if (!MI.isCopy()) @@ -1175,7 +1185,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 (sizeNoDbg(*BB) > SinkLoadInstsPerBlockThreshold || HandledDomBlocks.size() > SinkLoadBlocksThreshold) { for (auto *DomBB : HandledDomBlocks) { if (DomBB != BB && DT->dominates(DomBB, BB)) @@ -1277,7 +1287,7 @@ dbgs() << "CycleSink: Not sinking, sink block is the preheader\n"); return false; } - if (SinkBlock->size() > SinkLoadInstsPerBlockThreshold) { + if (sizeNoDbg(*SinkBlock) > SinkLoadInstsPerBlockThreshold) { LLVM_DEBUG( dbgs() << "CycleSink: Not Sinking, block too large to analyse.\n"); return false;