code: def test_dyn_shared_reuse_and_merge():
      n = 64
      A = te.placeholder((n,), name="A", dtype="float32")
      B = te.placeholder((n,), name="B", dtype="float32")
      C = te.placeholder(
          (te.size_var("n_dyn"),), name="C", dtype="float32"
      )
  
      def test_device_ir(A, B, C, D):
          ib = tvm.tir.ir_builder.create()
  
          tx = te.thread_axis("threadIdx.x")
          ib.scope_attr(tx, "thread_extent", n)
  
          A_sh = ib.allocate(
              A.dtype, (n,), scope="shared.dyn", name="A_sh"
          )
          B_sh = ib.allocate(
              B.dtype, (n,), scope="shared.dyn", name="B_sh"
          )
          C_sh = ib.allocate(
              C.dtype, (C.shape[0],), scope="shared.dyn", name="C_sh"
          )
  
          Aptr = ib.buffer_ptr(A)
          Bptr = ib.buffer_ptr(B)
          Cptr = ib.buffer_ptr(C)
          Dptr = ib.buffer_ptr(D)
  
          A_sh[tx] = Aptr[tx]
          Dptr[tx] = A_sh[tx]
  
          B_sh[tx] = Bptr[tx]
          Dptr[tx] += B_sh[tx]
  
          C_sh[tx] = Cptr[
              tx
          ]  # C cannot reuse other buffers since it size is dynamic
          Dptr[tx] += C_sh[tx]
  
          return ib.get()
  
      D = te.extern(
          (n,),
          [A, B, C],
          lambda ins, outs: test_device_ir(
              ins[0], ins[1], ins[2], outs[0]
          ),
          name="vadd",
          dtype="float32",
      )
      s = te.create_schedule(D.op)
  
      mod = run_passes(s, [A, B, C, D])
      # merged allocation
      # allocate(buf_dyn_shmem: Pointer(shared.dyn uint8), uint8, [((n_dyn*4) + 256)]);
      verify_single_allocation(mod["main"].body)
  
      def check_target(target):
          if not tvm.testing.device_enabled(target):
              return
  
          fadd = tvm.build(s, [A, B, C, D], target)
          dev = tvm.device(target, 0)
  
          a = tvm.nd.array(
              np.random.uniform(size=n).astype(A.dtype), dev
          )
          b = tvm.nd.array(
              np.random.uniform(size=n).astype(B.dtype), dev
          )
          c = tvm.nd.array(
              np.random.uniform(size=n).astype(C.dtype), dev
          )
          d = tvm.nd.array(np.zeros((n,), dtype=D.dtype), dev)
          fadd(a, b, c, d)
          tvm.testing.assert_allclose(
              d.numpy(), a.numpy() + b.numpy() + c.numpy(), 1e-4, 1e-4
          )
  
      for target in ["cuda", "nvptx"]:
          check_target(target)
  
imports: import numpy
  import tvm
  import tvm.testing
  from tvm import te
  from tvm.driver.build_module import schedule_to_module
  from tvm.topi.math import cast
  from tvm.script import tir
label_desc: Use image node_id 5 for calling a global function with example usage: test_dyn_shared_reuse_and_merge() and returns: ib