From 49fdddef8d461b0d512702d41a5b72bdfd4223b0 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Thu, 4 Jun 2020 17:52:03 +0800 Subject: [PATCH] fix(gopt): fix reorder arith chain pass GitOrigin-RevId: d3257ac43a69d37176896acfebaf1897ca213f05 --- src/gopt/impl/basic_arith/chain.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gopt/impl/basic_arith/chain.cpp b/src/gopt/impl/basic_arith/chain.cpp index 93bba09bf..c345e17ff 100644 --- a/src/gopt/impl/basic_arith/chain.cpp +++ b/src/gopt/impl/basic_arith/chain.cpp @@ -617,6 +617,16 @@ VarNode* ReorderArithChainPass::Impl::reduce_shp2terms(Mode mode) { } } + { + // sorted by id(), so the same set of input terms would get the + // same reduced var + auto cmp = [](const ShapedVars::value_type &a, + const ShapedVars::value_type &b) { + return a.second->id() < b.second->id(); + }; + small_sort(m_const_terms.begin(), m_const_terms.end(), cmp); + small_sort(m_nonconst_terms.begin(), m_nonconst_terms.end(), cmp); + } merge_shaped_terms(mode, m_const_terms, true); auto &&all_terms = m_const_terms; -- GitLab