code: def test_reuse_call_merge():
      r"""Test composite function is correctly produced from simple graph
         which re-uses call nodes.
  
      We could expect the pattern `make_add_add_add` to be merged
      into a single op `add_add_add`.
  
          x     y
           \   / \
            sub  |           x     y
          /  |  /             \   / |
          | add      ====>     sub  |
           \ |  \               |  /
            add |           add_add_add
             | /
            add
  
      """
      pattern_table = [("add_add_add", make_add_add_add_pattern())]
  
      def before():
          a = relay.var("a", shape=(10, 10))
          b = relay.var("b", shape=(10, 10))
          sub_node = relay.subtract(a, b)
  
          # pattern
          add_node = relay.add(sub_node, b)
          add_node_1 = relay.add(sub_node, add_node)
          r = relay.add(add_node_1, add_node)
  
          return relay.Function([a, b], r)
  
      def expected():
          a = relay.var("a", shape=(10, 10))
          b = relay.var("b", shape=(10, 10))
  
          # add_relu_add function
          in_1 = relay.var("in_1", shape=(10, 10))
          in_2 = relay.var("in_2", shape=(10, 10))
          add_node = relay.add(in_1, in_2)
          add_node_1 = relay.add(in_1, add_node)
          add_node_2 = relay.add(add_node_1, add_node)
          add_add_add = relay.Function([in_1, in_2], add_node_2)
          add_add_add = add_add_add.with_attr(
              "Composite", "add_add_add"
          )
          add_add_add = add_add_add.with_attr(
              "PartitionedFromPattern", "add_add_add_"
          )
  
          # merged function
          sub_node = relay.subtract(a, b)
          call = relay.Call(add_add_add, [sub_node, b])
          return relay.Function([a, b], call)
  
      check_result(pattern_table, before(), expected())
  
imports: import pytest
  import tvm
  from tvm import relay, tir
  from tvm.relay.dataflow_pattern import TuplePattern, TupleGetItemPattern, is_op, wildcard
  from tvm.relay.testing import run_opt_pass
label_desc: Use image node_id 10 for calling a global function with example usage: test_reuse_call_merge() and returns: relay, relay