From aeb43e5167466765215b98c30e7caca25f345f17 Mon Sep 17 00:00:00 2001 From: Margaret_wangrui Date: Wed, 17 Mar 2021 20:16:34 +0800 Subject: [PATCH] eliminate consecutive loads --- .../frontend/optimizer/irpass/load_eliminate.cc | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/load_eliminate.cc b/mindspore/ccsrc/frontend/optimizer/irpass/load_eliminate.cc index 9a2785c51ed..ec962cea25a 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/load_eliminate.cc +++ b/mindspore/ccsrc/frontend/optimizer/irpass/load_eliminate.cc @@ -24,27 +24,16 @@ #include "frontend/operator/ops.h" namespace mindspore::opt::irpass { -namespace { -// Return true if the node has Ref abstract. -bool HasAbstractRef(const AnfNodePtr &node) { - if (node == nullptr) { - return false; - } - auto &abs = node->abstract(); - return (abs != nullptr) && abs->isa(); -} -} // namespace - AnfNodePtr LoadEliminater::operator()(const OptimizerPtr &, const AnfNodePtr &node) { auto load_node = dyn_cast(node); if (load_node == nullptr || load_node->inputs().empty()) { MS_LOG(WARNING) << "LoadEliminater encounter invalid node: " << node->DebugString(); return nullptr; } + auto load_cnode = load_node->cast(); constexpr size_t kFirstInputIndex = 1; - auto ¶m = load_node->inputs().at(kFirstInputIndex); - if (!HasAbstractRef(param)) { - return param; + if (IsPrimitiveCNode(load_cnode->input(kFirstInputIndex), prim::kPrimLoad)) { + return load_cnode->input(kFirstInputIndex); } return nullptr; }