[Mlir-commits] [mlir] [mlir] Handle arith.const expr in dispatchIndexOpFoldResult func (PR #122432)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Jan 15 09:37:24 PST 2025


MaheshRavishankar wrote:

> OK, I understand now what you are trying to do. In my opinion, the input IR is invalid. We should make the verifier stricter to reject such ops.
> 
> Invalid:
> 
> ```mlir
>   %expand = tensor.expand_shape %collapse [[0], [1], [2, 3]]
>               output_shape [%s0, %s1, %c2, %c3] : tensor<?x4x6xf32> into tensor<?x4x2x3xf32>
> ```
> 
> Valid:
> 
> ```mlir
>   %expand = tensor.expand_shape %collapse [[0], [1], [2, 3]]
>               output_shape [%s0, 4, 2, 3] : tensor<?x4x6xf32> into tensor<?x4x2x3xf32>
> ```
> 
> The valid IR works with `-test-tensor-transform-patterns=test-expand-shape-bubbling`.
> 
> As for the reason why the first one should be invalid and the second one is valid, take a look a this discussion: https://discourse.llvm.org/t/tensor-ops-with-dynamic-sizes-which-behaviour-is-more-correct/82612. We were discussing the same issue in the context of `tensor.pack` and came to that conclusion.

Ok, I misread the IR... I agree with what Mathias says here. The following are valid

Valid:

```mlir
  %expand = tensor.expand_shape %collapse [[0], [1], [2, 3]]
              output_shape [%s0, 4, 2, 3] : tensor<?x4x6xf32> into tensor<?x4x2x3xf32>
```

or 

```mlir
  %expand = tensor.expand_shape %collapse [[0], [1], [2, 3]]
              output_shape [%s0, %s1, %c2, %c3] : tensor<?x4x6xf32> into tensor<?x4x?x?xf32>
```

but this should be invalid

> ```mlir
>   %expand = tensor.expand_shape %collapse [[0], [1], [2, 3]]
>               output_shape [%s0, %s1, %c2, %c3] : tensor<?x4x6xf32> into tensor<?x4x2x3xf32>
> ```

That is inconsistent...


https://github.com/llvm/llvm-project/pull/122432


More information about the Mlir-commits mailing list