[unroll] Use a small set to de-duplicate operands prior to putting them
authorChandler Carruth <chandlerc@gmail.com>
Fri, 13 Feb 2015 03:48:38 +0000 (03:48 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 13 Feb 2015 03:48:38 +0000 (03:48 +0000)
into the worklist. This avoids allocating lots of worklist memory for
them when there are large numbers of repeated operands.

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

lib/Transforms/Scalar/LoopUnrollPass.cpp

index bffaec013360b8ee67760fd6dad0b7587b4be66c..e4771dbc89b70bda4a07c25508990c3647bfaa7b 100644 (file)
@@ -503,6 +503,12 @@ public:
     SmallVector<Instruction *, 8> Worklist;
     SmallPtrSet<Instruction *, 16> DeadInstructions;
 
+    // We keep a very small set of operands that we use to de-duplicate things
+    // when inserting into the worklist. This lets us handle duplicates within
+    // a single instruction's operands without buring lots of memory on the
+    // worklist.
+    SmallPtrSet<Instruction *, 4> OperandSet;
+
     // Start by initializing worklist with simplified instructions.
     for (auto &FoldedKeyValue : SimplifiedValues)
       if (auto *FoldedInst = dyn_cast<Instruction>(FoldedKeyValue.first)) {
@@ -510,9 +516,11 @@ public:
 
         // Add each instruction operand of this dead instruction to the
         // worklist.
+        OperandSet.clear();
         for (auto *Op : FoldedInst->operand_values())
           if (auto *OpI = dyn_cast<Instruction>(Op))
-            Worklist.push_back(OpI);
+            if (OperandSet.insert(OpI).second)
+              Worklist.push_back(OpI);
       }
 
     // If a definition of an insn is only used by simplified or dead
@@ -537,9 +545,11 @@ public:
       if (AllUsersFolded) {
         NumberOfOptimizedInstructions += TTI.getUserCost(I);
         DeadInstructions.insert(I);
+        OperandSet.clear();
         for (auto *Op : I->operand_values())
           if (auto *OpI = dyn_cast<Instruction>(Op))
-            Worklist.push_back(OpI);
+            if (OperandSet.insert(OpI).second)
+              Worklist.push_back(OpI);
       }
     }
     return NumberOfOptimizedInstructions;