[unroll] Change the other worklist in the unroll analyzer to be a set
authorChandler Carruth <chandlerc@gmail.com>
Fri, 13 Feb 2015 04:27:50 +0000 (04:27 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 13 Feb 2015 04:27:50 +0000 (04:27 +0000)
vector.

In addition to dramatically reducing the work required for contrived
example loops, this also has to correct some serious latent bugs in the
cost computation. Previously, we might add an instruction onto the
worklist once for every load which it used and was simplified. Then we
would visit it many times and accumulate "savings" each time.

I mean, fortunately this couldn't matter for things like calls with 100s
of operands, but even for binary operators this code seems like it must
be double counting the savings.

I just noticed this by inspection and due to the runtime problems it can
introduce, I don't have any test cases for cases where the cost produced
by this routine is unacceptable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229059 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopUnrollPass.cpp

index ccc4a248476e3cea13fa309ac057360883f0566b..0851f436904e184a4c71a8144affe3dc4053ea76 100644 (file)
@@ -456,7 +456,7 @@ public:
   // values for the given Iteration.
   // Fill in SimplifiedValues map for future use in DCE-estimation.
   unsigned estimateNumberOfSimplifiedInstructions(unsigned Iteration) {
-    SmallVector<Instruction *, 8> Worklist;
+    SmallSetVector<Instruction *, 8> Worklist;
     SimplifiedValues.clear();
     CountedInstructions.clear();
     NumberOfOptimizedInstructions = 0;
@@ -474,7 +474,7 @@ public:
           continue;
         if (!L->contains(UI))
           continue;
-        Worklist.push_back(UI);
+        Worklist.insert(UI);
       }
     }
 
@@ -491,7 +491,7 @@ public:
           continue;
         if (!L->contains(UI))
           continue;
-        Worklist.push_back(UI);
+        Worklist.insert(UI);
       }
     }
     return NumberOfOptimizedInstructions;