[PATCH] D70030: [MachineBlockPlacement] Update UnscheduledPredecessors when tail duplicate delete a block.

Huihui Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 8 15:19:58 PST 2019


huihuiz created this revision.
huihuiz added reviewers: rnk, arsenm, fedor.sergeev, philip.pfaffe, chandlerc, apazos, efriedma, davidxl, ZhangKang, Carrot.
huihuiz added a project: LLVM.
Herald added subscribers: hiraditya, wdng.
huihuiz added a comment.

This problem caused assertion on: Assertion `BlockToChain[&MBB]->UnscheduledPredecessors == 0 && "expect unschedPred to be 0\n"' failed.

My apologies for not able to get a test case here. I try really hard to reduce a test case, but failed.


When filling worklist, UnscheduledPredecessors counter is increased whenever
a MBB within a BlockChain has any predecessor with different BlockChain. This
counter is decreased during buildChain (scheduled), by walking through every
successor of MBB within the BlockChain, decrease when successor BlockChain is
different from current BlockChain.

However, tail duplicator will delete MBB and update CFG, therefore a previously
increased UnscheduledPredecessors count will not be decreased, causing assertion
of "Attempting to place block with unscheduled predecessors in worklist." when
trying to fill worklist later on.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70030

Files:
  llvm/lib/CodeGen/MachineBlockPlacement.cpp


Index: llvm/lib/CodeGen/MachineBlockPlacement.cpp
===================================================================
--- llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -2948,9 +2948,21 @@
 
   SmallVector<MachineBasicBlock *, 8> DuplicatedPreds;
   bool IsSimple = TailDup.isSimpleBB(BB);
+  BlockChain &BBChain = *BlockToChain[BB];
   TailDup.tailDuplicateAndUpdate(IsSimple, BB, LPred,
                                  &DuplicatedPreds, &RemovalCallbackRef);
 
+  // Decrease UnscheduledPredecessors previously set for BBChain, if BB is
+  // deleted during tail duplication.
+  if (Removed)
+    for (MachineBasicBlock *Pred : DuplicatedPreds) {
+      if (BlockFilter && !BlockFilter->count(Pred))
+        continue;
+      if (&BBChain != BlockToChain[Pred] &&
+          BBChain.UnscheduledPredecessors != 0)
+        --BBChain.UnscheduledPredecessors;
+    }
+
   // Update UnscheduledPredecessors to reflect tail-duplication.
   DuplicatedToLPred = false;
   for (MachineBasicBlock *Pred : DuplicatedPreds) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70030.228525.patch
Type: text/x-patch
Size: 1065 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191108/dd334d22/attachment.bin>


More information about the llvm-commits mailing list