[llvm] r229052 - [unroll] Use a small set to de-duplicate operands prior to putting them

Chandler Carruth chandlerc at gmail.com
Thu Feb 12 19:48:38 PST 2015


Author: chandlerc
Date: Thu Feb 12 21:48:38 2015
New Revision: 229052

URL: http://llvm.org/viewvc/llvm-project?rev=229052&view=rev
Log:
[unroll] Use a small set to de-duplicate operands prior to putting them
into the worklist. This avoids allocating lots of worklist memory for
them when there are large numbers of repeated operands.

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp?rev=229052&r1=229051&r2=229052&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp Thu Feb 12 21:48:38 2015
@@ -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;





More information about the llvm-commits mailing list