code: def check_tir_const_fold(
      dtype,
      foldf,
      calcf,
      x_range=None,
      y_range=None,
      expect=None,
      skip_overflow=False,
  ):
      """Helper to check constant folding behavior
  
      Parameters
      ----------
      dtype: str
          Datatype of constants
  
      foldf: (x, y) -> z
          Folding function to call
  
      calcf: (x, y) -> z
          Compiled calculation function to call
  
      x_range: Union[int, float, tuple]
          Single value or value range [min, max]
  
      y_range: Union[int, float, tuple]
          Single value or value range [min, max]
  
      expect: Union[int, float]
          Expected calculation result
  
      skip_overflow: bool
          Skip assertion if the overflow happens
      """
      seed = random.randint(0, 2147483648)
      np.random.seed(seed)
      ninfo = (
          np.finfo(dtype)
          if dtype.startswith("float")
          else np.iinfo(dtype)
      )
  
      if x_range is None:
          x_range = (ninfo.min, ninfo.max)
      if isinstance(x_range, (int, float)):
          x = x_range
      elif dtype.startswith("int") or dtype.startswith("uint"):
          x = np.random.randint(x_range[0], x_range[1] + 1, dtype=dtype)
      else:
          x = np.random.uniform(x_range[0], x_range[1])
  
      if y_range is None:
          y_range = (ninfo.min, ninfo.max)
      if isinstance(y_range, (int, float)):
          y = y_range
      elif dtype.startswith("int") or dtype.startswith("uint"):
          y = np.random.randint(y_range[0], y_range[1] + 1, dtype=dtype)
      else:
          y = np.random.uniform(y_range[0], y_range[1])
  
      if skip_overflow:
          py_res = foldf(x, y)
          if isinstance(py_res, (tir.IntImm, tir.FloatImm)):
              py_res = py_res.value
          if not (ninfo.min <= py_res <= ninfo.max):
              # If the result overflow, certain arithmetics is non-defined
              # thus we intentionally do not make the test failed.
              return
  
      fold_res = foldf(tir.const(x, dtype), tir.const(y, dtype))
      calc_res = calcf(x, y)
  
      flaky_msg = (
          f"{dtype} ({x}, {y}, {expect}) const folding check failed.\n"
          + "This test is intentionally non-deterministic, "
          + f"if it fails please report it in github issue together with this seed {seed}\n"
      )
      if dtype.startswith("float"):
          compare_float_value(calc_res, fold_res.value, flaky_msg)
          if expect:
              compare_float_value(expect, calc_res, flaky_msg)
      else:
          assert calc_res == fold_res.value, flaky_msg
          if expect:
              assert expect == calc_res, flaky_msg
  
imports: import math
  import random
  import numpy
  import tvm
  import tvm.testing
  import pytest
  from tvm import tir
  from tvm.script import tir
  import pytest
label_desc: Use image node_id 11 for calling a global function with example usage: check_tir_const_fold(dtype, foldf, calcf, x_range, y_range, expect, skip_overflow) without return types