[PATCH] Estimate DCE effect in heuristic for estimating complete-unroll optimization effects.

Michael Zolotukhin mzolotukhin at apple.com
Thu Apr 23 16:36:35 PDT 2015


Rebase to trunk.


http://reviews.llvm.org/D8817

Files:
  lib/Transforms/Scalar/LoopUnrollPass.cpp

Index: lib/Transforms/Scalar/LoopUnrollPass.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -359,6 +359,11 @@
   // post-unrolling.
   DenseMap<Value *, Constant *> SimplifiedValues;
 
+  // Similarly, we keep track of all instructions that become dead.
+  // We don't need to map them to a value, that's why we use Set instead of Map
+  // here.
+  SmallPtrSet<Instruction *, 16> DeadInstructions;
+
   // To avoid requesting SCEV info on every iteration, request it once, and
   // for each value that would become ConstAddress+Constant after loop
   // unrolling, save the corresponding data.
@@ -533,6 +538,7 @@
     // we literally have to go through all loop's iterations.
     for (Iteration = 0; Iteration < TripCount; ++Iteration) {
       SimplifiedValues.clear();
+      DeadInstructions.clear();
       BBWorklist.clear();
       BBWorklist.insert(L->getHeader());
       // Note that we *must not* cache the size, this loop grows the worklist.
@@ -563,6 +569,24 @@
       // won't find them on later ones too.
       if (!NumberOfOptimizedInstructions)
         return false;
+      for (unsigned Idx = BBWorklist.size() - 1; Idx != 0; --Idx) {
+        BasicBlock *BB = BBWorklist[Idx];
+        if (BB->empty())
+          continue;
+        for (BasicBlock::reverse_iterator I = BB->rbegin(), E = BB->rend(); I != E; ++I) {
+          if (SimplifiedValues.count(&*I))
+            continue;
+          if (DeadInstructions.count(&*I))
+            continue;
+          if (std::all_of(I->user_begin(), I->user_end(), [&](User *U) {
+                return SimplifiedValues.count(cast<Instruction>(U)) +
+                       DeadInstructions.count(cast<Instruction>(U));
+                })) {
+            NumberOfOptimizedInstructions += TTI.getUserCost(&*I);
+            DeadInstructions.insert(&*I);
+          }
+        }
+      }
     }
     return true;
   }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8817.24344.patch
Type: text/x-patch
Size: 2003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150423/e0400d3a/attachment.bin>


More information about the llvm-commits mailing list