comaniac commented on a change in pull request #5931:
URL: https://github.com/apache/incubator-tvm/pull/5931#discussion_r445901105



##########
File path: src/relay/transforms/eliminate_common_subexpr.cc
##########
@@ -58,27 +58,52 @@ class CommonSubexprEliminator : public ExprMutator {
 
     auto it = expr_map_.find(new_call->op);
     if (it != expr_map_.end()) {
-      for (const CallNode* candidate : it->second) {
-        bool is_equivalent = true;
-        if (!attrs_equal(new_call->attrs, candidate->attrs)) {
-          continue;
+      for (const Expr& candidate_expr : it->second) {
+        if (const CallNode* candidate = candidate_expr.as<CallNode>()) {
+          bool is_equivalent = true;
+          if (!attrs_equal(new_call->attrs, candidate->attrs)) {
+            continue;
+          }
+          for (size_t i = 0; i < new_call->args.size(); i++) {
+            if (!new_call->args[i].same_as(candidate->args[i]) &&
+                !IsEqualScalar(new_call->args[i], candidate->args[i])) {
+              is_equivalent = false;
+              break;
+            }
+          }
+          if (!is_equivalent) continue;
+          return GetRef<Call>(candidate);
         }
-        for (size_t i = 0; i < new_call->args.size(); i++) {
-          if (!new_call->args[i].same_as(candidate->args[i]) &&
-              !IsEqualScalar(new_call->args[i], candidate->args[i])) {
-            is_equivalent = false;
-            break;
+      }
+    }
+    expr_map_[new_call->op].push_back(new_expr);
+    return new_expr;
+  }
+
+  Expr VisitExpr_(const TupleGetItemNode* op) final {
+    Expr new_expr = ExprMutator::VisitExpr_(op);
+    const TupleGetItemNode* new_tuple = new_expr.as<TupleGetItemNode>();

Review comment:
       `new_tuple` is a bit confusing as this is not actually a `tuple`. Maybe 
`new_tuple_item` would be better?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to