[PATCH] D41572: [MachineTraceMetrics] Fix bug in pickTracePred

Hsiangkai Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 25 00:51:58 PST 2017


HsiangKai created this revision.
HsiangKai added reviewers: majnemer, stoklund.

The definition of InstrDepth for a basic block is the accumulated number
of instructions in the trace above the block, excluding instructions in
the block. When we pick the best trace predecessor, we should consider
the block depth of each predecessor and pick the smallest one. The
original implementation uses current block's InstrCount to calculate
predecessors' InstrDepth. It should be fixed to use predecessors'
InstrCount instead of current block's InstrCount.


https://reviews.llvm.org/D41572

Files:
  lib/CodeGen/MachineTraceMetrics.cpp


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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41572.128127.patch
Type: text/x-patch
Size: 1049 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171225/ce39761a/attachment.bin>


More information about the llvm-commits mailing list