[Mlir-commits] [mlir] [MLIR][Tensor] Remove FoldDimOf[Expand|Collapse]Shape Pattern (PR #134219)

Mehdi Amini llvmlistbot at llvm.org
Thu Apr 10 04:59:18 PDT 2025


joker-eph wrote:

I chatted with @Groverkss and we identified the reason these can't work well as canonicalization. It isn't visible on collapse_shape example because they trigger a multiplication operation, however it becomes very visible on the expand_shape operation which introduces a `floor_div`. The problem is that this is an **information loss** that can't be just recovered easily. The `expand_shape` guarantees an "exact division", which can't be expressed with affine_apply apparently. Losing information is obviously never OK in canonicalization.

Please update the PR description accordingly please @vivekkhandelwal1, something like:

> Remove tensor.dim canonicalization patterns registered on  tensor.expand_shape/tensor.collapse_shape.
>
> These are problematic because the iterative application that locally resolves the tensor.dim operation introduces
> intermediate floor_div which are losing the information about the exact division that was carried out in the original
> IR, and the iterative algorithm can't converge towards the simplest form.
> Information loss is not acceptable for a canonicalization.
>
> Resolving the dimOp can be achieved through <insert here>


I'm not sure about the last part though: where is the pass that demonstrates the use of ReifyRankedShapedTypeOpInterface to fold all this?


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


More information about the Mlir-commits mailing list