[mlir][tensor] Fold when source is const (#71643)
Fixes https://github.com/llvm/llvm-project/issues/60656. This patch implements a basic fold for various reshape/resize tensor operations. Specifically, the folding removes tensor reshape/resize ops when they are applied to a constant tensor. For example, the following function: ```mlir func.func @main(%dest : tensor<8x16x8x32xf32>) -> tensor<8x16x8x32xf32> { %cst = arith.constant dense<1.000000e-01> : tensor<64x128xf32> %0 = tensor.pack %cst outer_dims_perm = [1, 0] inner_dims_pos = [0, 1] inner_tiles = [8, 32] into %dest : tensor<64x128xf32> -> tensor<8x16x8x32xf32> return %0 : tensor<8x16x8x32xf32> } ``` will be changed into the following with `mlir-opt -canonicalize`: ```mlir func.func @main(%arg0: tensor<8x16x8x32xf32>) -> tensor<8x16x8x32xf32> { %cst = arith.constant dense<1.000000e-01> : tensor<8x16x8x32xf32> return %cst : tensor<8x16x8x32xf32> } ``` As a side-note, this patch is essentially an extension of https://github.com/llvm/llvm-project/commit/f79f430d4b268429f96be95622facd2775b25624.
parent
bede0106
Please register or sign in to comment