From 7837a2b037f5bc278d1ca12a4d55eda6233be4f1 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Fri, 2 Dec 2016 00:11:01 +0000 Subject: [PATCH] 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. llvm-svn: 288441 --- lib/CodeGen/SelectionDAG/LegalizeTypes.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp b/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp index 4e34a579ad5..84703425428 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp @@ -484,7 +484,7 @@ SDNode *DAGTypeLegalizer::AnalyzeNewNode(SDNode *N) { // updated after all operands have been analyzed. Since this is rare, // the code tries to minimize overhead in the non-morphing case. - SmallVector NewOps; + std::vector 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(SDNode *N) { 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); } }