[Mlir-commits] [mlir] [MLIR][Tensor] Remove tensor.dim canonicalization patterns registered on tensor.expand_shape/tensor.collapse_shape (PR #134219)

Vivek Khandelwal llvmlistbot at llvm.org
Thu Apr 10 05:47:10 PDT 2025


vivekkhandelwal1 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 `resolve-ranked-shaped-type-result-dims` and
> > `resolve-shaped-type-result-dims` passes.

@joker-eph I have made the changes as asked. Thanks!

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


More information about the Mlir-commits mailing list