tvm_tirx.tirx.transform.CommonSubexprElim#
- tvm_tirx.tirx.transform.CommonSubexprElim()#
Replace redundant computations by new variables.
- Returns:
fpass (tvm_tirx.ir.transform.Pass) – The result pass
Examples
import tvm_tirx as tvm from tvm_tirx.script import ir as I, tirx as T from tvm_tirx.tirx import transform as tr @I.ir_module class Before: @T.function(private=True) def main(B: T.Tensor((2,), T.int32), x: T.int32, y: T.int32): B[0] = x + y B[1] = x + y @I.ir_module class Expected: @T.function(private=True) def main(B: T.Tensor((2,), T.int32), x: T.int32, y: T.int32): cse_v1: T.let[T.int32] = x + y B[0] = cse_v1 B[1] = cse_v1 def run_pass(): return tr.CommonSubexprElim()(Before) tvm.ir.assert_structural_equal(run_pass(), Expected)