[llvm] r288441 - SDAG: Avoid a large, usually empty SmallVector in a recursive function

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 1 16:11:01 PST 2016


Author: bogner
Date: Thu Dec  1 18:11:01 2016
New Revision: 288441

URL: http://llvm.org/viewvc/llvm-project?rev=288441&view=rev
Log:
SDAG: Avoid a large, usually empty SmallVector in a recursive function

This SmallVector is using up 128 bytes on the stack every time despite
almost always being empty[1], and since this function can recurse quite
deeply that adds up to a lot of overhead. We've seen this run afoul of
ulimits in some cases with ASAN on.

Replacing the SmallVector with a std::vector trades an occasional heap
allocation for vastly less stack usage.

[1]: I gathered some stats on an internal test suite and the vector
was non-empty in only 45,000 of 10,000,000 calls to this function.

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp?rev=288441&r1=288440&r2=288441&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp Thu Dec  1 18:11:01 2016
@@ -484,7 +484,7 @@ SDNode *DAGTypeLegalizer::AnalyzeNewNode
   // updated after all operands have been analyzed.  Since this is rare,
   // the code tries to minimize overhead in the non-morphing case.
 
-  SmallVector<SDValue, 8> NewOps;
+  std::vector<SDValue> NewOps;
   unsigned NumProcessed = 0;
   for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
     SDValue OrigOp = N->getOperand(i);
@@ -500,7 +500,7 @@ SDNode *DAGTypeLegalizer::AnalyzeNewNode
       NewOps.push_back(Op);
     } else if (Op != OrigOp) {
       // This is the first operand to change - add all operands so far.
-      NewOps.append(N->op_begin(), N->op_begin() + i);
+      NewOps.insert(NewOps.end(), N->op_begin(), N->op_begin() + i);
       NewOps.push_back(Op);
     }
   }




More information about the llvm-commits mailing list