[PATCH] D89818: [Compile Time] Make it possible to skip redundant debuginst removal

Christopher Tetreault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 20 14:05:45 PDT 2020


ctetreau updated this revision to Diff 299466.
ctetreau added a comment.

address code review issues


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89818/new/

https://reviews.llvm.org/D89818

Files:
  llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
  llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
  llvm/lib/Transforms/Utils/LoopUnroll.cpp


Index: llvm/lib/Transforms/Utils/LoopUnroll.cpp
===================================================================
--- llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -234,6 +234,7 @@
       if (isInstructionTriviallyDead(Inst))
         BB->getInstList().erase(Inst);
     }
+    RemoveRedundantDbgInstrs(BB);
   }
 
   // TODO: after peeling or unrolling, previously loop variant conditions are
@@ -862,7 +863,10 @@
     if (Term && Term->isUnconditional()) {
       BasicBlock *Dest = Term->getSuccessor(0);
       BasicBlock *Fold = Dest->getUniquePredecessor();
-      if (MergeBlockIntoPredecessor(Dest, &DTU, LI)) {
+      // Deferring redundant debug value elimination. For sufficiently
+      // complicated loop bodies, this can result in multi-minute compile times.
+      if (MergeBlockIntoPredecessor(Dest, &DTU, LI, nullptr, nullptr, false,
+                                    true)) {
         // Dest has been folded into Fold. Update our worklists accordingly.
         std::replace(Latches.begin(), Latches.end(), Dest, Fold);
         UnrolledLoopBlocks.erase(std::remove(UnrolledLoopBlocks.begin(),
Index: llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -172,7 +172,8 @@
 bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
                                      LoopInfo *LI, MemorySSAUpdater *MSSAU,
                                      MemoryDependenceResults *MemDep,
-                                     bool PredecessorWithTwoSuccessors) {
+                                     bool PredecessorWithTwoSuccessors,
+                                     bool SkipRedundantDebugValElimination) {
   if (BB->hasAddressTaken())
     return false;
 
@@ -285,10 +286,12 @@
   // Add unreachable to now empty BB.
   new UnreachableInst(BB->getContext(), BB);
 
-  // Eliminate duplicate/redundant dbg.values. This seems to be a good place to
-  // do that since we might end up with redundant dbg.values describing the
-  // entry PHI node post-splice.
-  RemoveRedundantDbgInstrs(PredBB);
+  if (!SkipRedundantDebugValElimination) {
+    // Eliminate duplicate/redundant dbg.values. This seems to be a good place
+    // to do that since we might end up with redundant dbg.values describing the
+    // entry PHI node post-splice.
+    RemoveRedundantDbgInstrs(PredBB);
+  }
 
   // Inherit predecessors name if it exists.
   if (!PredBB->hasName())
Index: llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
===================================================================
--- llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -91,11 +91,16 @@
 /// if BB's Pred has a branch to BB and to AnotherBB, and BB has a single
 /// successor Sing. In this case the branch will be updated with Sing instead of
 /// BB, and BB will still be merged into its predecessor and removed.
+///
+/// Pass True to SkipRedundantDebugValElimination in order to skip redundant
+/// debug val elimination. This elimination has O(#instructions) time
+/// complexity, and may result in unreasonably long compile times.
 bool MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU = nullptr,
                                LoopInfo *LI = nullptr,
                                MemorySSAUpdater *MSSAU = nullptr,
                                MemoryDependenceResults *MemDep = nullptr,
-                               bool PredecessorWithTwoSuccessors = false);
+                               bool PredecessorWithTwoSuccessors = false,
+                               bool SkipRedundantDebugValElimination = false);
 
 /// Merge block(s) sucessors, if possible. Return true if at least two
 /// of the blocks were merged together.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89818.299466.patch
Type: text/x-patch
Size: 3938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201020/55b1b22a/attachment.bin>


More information about the llvm-commits mailing list