def test_fused_elementwise_indirect_input_dependency_split_subgraph(self, dtype):
        r"""
                X0[M,K] X1[]
                 \      /
                  Add_1      X2[K,N]
                   |    \      /
                   |     Gemm_1
                   |        |
        X3[P,M,N]  |      Tanh_1 (output)
              \    |           |
                Sub_1          |
                   |          /
                Sub_2 (output)
            Tanh_1 and Sub_1 should be fused together.
        """
        target = detect_target()
        if dtype == "float" and (int(target._arch) < 80 or target.name == "rocm"):
            self.skipTest("gemm with float tensors requires CUDA sm >= 80")

        M = 10
        K = 4
        N = 4
        P = 15
        X0 = Tensor(
            shape=[M, K],
            dtype=dtype,
            name="X0",
            is_input=True,
        )
        X1 = Tensor(
            shape=[],
            dtype=dtype,
            name="X1",
            value=3.0,
        )
        X2 = Tensor(
            shape=[K, N],
            dtype=dtype,
            name="X2",
            is_input=True,
        )
        X3 = Tensor(
            shape=[P, M, N],
            dtype=dtype,
            name="X3",
            is_input=True,
        )

        R0 = ops.elementwise(FuncEnum.ADD)(X0, X1)
        R1 = ops.gemm_rcr()(R0, X2)
        R2 = ops.elementwise(FuncEnum.TANH)(R1)
        R3 = ops.elementwise(FuncEnum.SUB)(X3, R0)
        R4 = ops.elementwise(FuncEnum.SUB)(R3, R2)
        R3._attrs["name"] = "R3"
        R3._attrs["is_output"] = True
        R4._attrs["name"] = "R4"
        R4._attrs["is_output"] = True

        module = compile_model(
            [R3, R4],
            target,
            "./tmp",
            f"fused_elementwise_indirect_input_dependency_split_subgraph{dtype}",
        )
        debug_sorted_graph = module.debug_sorted_graph
        sorted_ops = graph_utils.get_sorted_ops(debug_sorted_graph)
        self.assertEqual(len(sorted_ops), 4)

        x0_pt = get_random_torch_tensor([M, K], dtype)
        x2_pt = get_random_torch_tensor([K, N], dtype)
        x3_pt = get_random_torch_tensor([P, M, N], dtype)

        r0_pt = x0_pt + 3
        r1_pt = nn.functional.linear(r0_pt, x2_pt)
        r2_pt = torch.tanh(r1_pt)
        r3_pt = x3_pt - r0_pt
        r4_pt = r3_pt - r2_pt

        r3 = get_torch_empty_tensor([P, M, N], dtype)
        r4 = get_torch_empty_tensor([P, M, N], dtype)

        input_name_to_idx_mapping = module.get_input_name_to_index_map()
        inputs = [None] * len(input_name_to_idx_mapping)
        input_name_to_pt_mapping = {
            "X0": x0_pt,
            "X2": x2_pt,
            "X3": x3_pt,
        }
        for input_name, pt in input_name_to_pt_mapping.items():
            inputs[input_name_to_idx_mapping[input_name]] = pt
        module.run_with_tensors(inputs, [r3, r4])
        self.assertTrue(torch.allclose(r3, r3_pt, atol=1e-2, rtol=1e-2))
        self.assertTrue(torch.allclose(r4, r4_pt, atol=1e-2, rtol=1e-2))

                X0[M,K] X1[]
                 \      /
                  Add_1      X2[K,N]
                   |    \      /
                   |     Gemm_1
                   |        |
        X3[P,M,N]  |      Tanh_1 (output)
              \    |           |
                Sub_1          |
                   |          /
                Sub_2 (output)
            Tanh_1 and Sub_1 should be fused together.
        
tests/unittest/compiler/test_fused_elementwise_complex_dependency.py