Index: lib/CodeGen/MachineTraceMetrics.cpp =================================================================== --- lib/CodeGen/MachineTraceMetrics.cpp +++ lib/CodeGen/MachineTraceMetrics.cpp @@ -331,17 +331,17 @@ // Don't leave loops, and never follow back-edges. if (CurLoop && MBB == CurLoop->getHeader()) return nullptr; - unsigned CurCount = MTM.getResources(MBB)->InstrCount; const MachineBasicBlock *Best = nullptr; unsigned BestDepth = 0; for (const MachineBasicBlock *Pred : MBB->predecessors()) { + unsigned PredInstrCount = MTM.getResources(Pred)->InstrCount; const MachineTraceMetrics::TraceBlockInfo *PredTBI = getDepthResources(Pred); // Ignore cycles that aren't natural loops. if (!PredTBI) continue; // Pick the predecessor that would give this block the smallest InstrDepth. - unsigned Depth = PredTBI->InstrDepth + CurCount; + unsigned Depth = PredTBI->InstrDepth + PredInstrCount; if (!Best || Depth < BestDepth) { Best = Pred; BestDepth = Depth;