diff --git a/paddle/fluid/pir/transforms/sub_graph_detector.cc b/paddle/fluid/pir/transforms/sub_graph_detector.cc index 57343056ee87a..913617c8e5b30 100644 --- a/paddle/fluid/pir/transforms/sub_graph_detector.cc +++ b/paddle/fluid/pir/transforms/sub_graph_detector.cc @@ -461,14 +461,13 @@ void SubgraphDetector::MergeSource2Target(const SubGraphPtr& source, SubgraphDetector::SubgraphDetector(pir::Block* block, const OpClassifier& classifier) { - // init sort_ops_ in reverse topo order and op2index_ in topo order + // init sort_ops_ in reverse topo order + sort_ops_ = InverselyTopologicalSort(block); + // init op2index_ in topo order int index = 0; for (auto& op : *block) { - sort_ops_.push_back(&op); op2index_[&op] = index++; } - std::reverse(sort_ops_.begin(), sort_ops_.end()); - // construct subgraphs and upstream/downstream relation std::vector subgraph_list; for (const auto& op : sort_ops_) {