diff --git a/src/pass/memory_optimize.cpp b/src/pass/memory_optimize.cpp index dc14bac15b2b09af7b822b0456a65105ec40b224..d9cfa1389955ed503f0aae12e3251e01d2fe9a13 100644 --- a/src/pass/memory_optimize.cpp +++ b/src/pass/memory_optimize.cpp @@ -118,10 +118,6 @@ void MemoryOptPass::operator()( } } - for (const auto &node : fetch_var_nodes) { - analysis_nodes_.push(node); - } - // apply optimize while (!analysis_nodes_.empty()) { auto *node = analysis_nodes_.top(); @@ -132,7 +128,9 @@ void MemoryOptPass::operator()( bool reused = false; // find out a possable reuse list for (auto &list : reused_nodes_) { - if (list.back()->count == 0) { + if (list.back()->count == 0 && + std::find(fetch_var_nodes.begin(), fetch_var_nodes.end(), + list.back()) == fetch_var_nodes.end()) { list.push_back(node); reused = true; break;