[all-commits] [llvm/llvm-project] d0da3d: [mlir][tensor] Fold when source is const (#71643)

Rik Huijzer via All-commits all-commits at lists.llvm.org
Thu Nov 9 11:37:06 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d0da3d8393939790bb1a6b3b5a36daeeef000c9b
      https://github.com/llvm/llvm-project/commit/d0da3d8393939790bb1a6b3b5a36daeeef000c9b
  Author: Rik Huijzer <github at huijzer.xyz>
  Date:   2023-11-09 (Thu, 09 Nov 2023)

  Changed paths:
    M mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td
    M mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
    M mlir/test/Dialect/Tensor/canonicalize.mlir

  Log Message:
  -----------
  [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.




More information about the All-commits mailing list