From ae6942ff9f874945185596cdb515c0005a5498a1 Mon Sep 17 00:00:00 2001 From: yujianfeng Date: Tue, 13 Oct 2020 10:26:22 +0800 Subject: [PATCH] Fix rebuilding nodes when eliminating redundant op --- .../backend/optimizer/pass/eliminate_redundant_op.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mindspore/ccsrc/backend/optimizer/pass/eliminate_redundant_op.cc b/mindspore/ccsrc/backend/optimizer/pass/eliminate_redundant_op.cc index 115f09fb60a..325acff9f9b 100644 --- a/mindspore/ccsrc/backend/optimizer/pass/eliminate_redundant_op.cc +++ b/mindspore/ccsrc/backend/optimizer/pass/eliminate_redundant_op.cc @@ -107,8 +107,12 @@ const AnfNodePtr ProcessMatchedNodes(const FuncGraphPtr &func_graph, const CNode } else { // rebuild the pass nodes for (size_t idx = pass_size - 2; idx > 0; --idx) { auto new_node = func_graph->NewCNode((*pass_vector)[idx].first->inputs()); - new_node->set_input((*pass_vector)[idx].second, - (*pass_vector)[idx + 1].first->input((*pass_vector)[idx + 1].second)); + if (idx == pass_size - 2) { + new_node->set_input((*pass_vector)[idx].second, + (*pass_vector)[idx + 1].first->input((*pass_vector)[idx + 1].second)); + } else { + new_node->set_input((*pass_vector)[idx].second, (*pass_vector)[idx + 1].first); + } (*pass_vector)[idx].first = new_node; } return (*pass_vector)[1].first;