[Mlir-commits] [mlir] [vector][mlir] Canonicalize to shape_cast where possible (PR #140583)

Kunwar Grover llvmlistbot at llvm.org
Wed Dec 17 07:30:58 PST 2025


Groverkss wrote:

Not only this, this pattern in that form has a bigger problem of it doesn't canonicalize to a single form depending on what order patterns are run in. Let's say we implement the transpose -> shape_cast pattern for unit dimensions:

```mlir
shape_cast: 1x2x2x2x3 -> 1x4x2x3
transpose: 1x4x2x3 -> 1x4x3x2
transpose: 1x4x3x2 -> 4x1x3x2
shape_cast: 4x1x3x2 -> 4x3x2
```

if the transpose -> shape_cast unit dim canonicalization runs first:

```mlir
shape_cast: 1x2x2x2x3 -> 1x4x2x3
transpose: 1x4x2x3 -> 1x4x3x2
shape_cast: 1x4x3x2 -> 4x3x2
```

You are stuck here now, unless we have the more general pattern i talked about before.

If you canonicalize transpose(transpose) first:

```mlir
shape_cast: 1x2x2x2x3 -> 1x4x2x3
transpose: 1x4x2x3 -> 4x1x3x2
shape_cast: 4x1x3x2 -> 4x3x2
```

and you are stuck here.

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


More information about the Mlir-commits mailing list