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

Andrzej Warzyński llvmlistbot at llvm.org
Sun Nov 2 13:48:04 PST 2025


banach-space wrote:

Hi everyone,

Here’s a quick summary from the LLVM Dev discussion (myself, @dcaballe , @MaheshRavishankar and @matthias-springer  were present):

We’ve reviewed this extensively, and I’ve seen no evidence that this change would:

* Drop information that cannot be recovered.
* Break something that cannot be fixed (*).

Neither Diego nor I see any technical issues with this PR - every concern raised so far can be addressed without difficulty (**). As one specific point, let me return to Kunwar’s example, i.e. a pattern matching:
```mlir
vector.transpose 1x2x2x8 -> 2x2x8x1
vector.contract { indexing_maps = [#map] }
```

to rewrite that as:
```mlir
vector.contract { indexing_maps = [#transposed_map] }
```

Such a pattern should also match:
```mlir
vector.shape_cast 8x8 -> 2x2x8x1
vector.contract { indexing_maps = [#map] }
```

Why? Because in this case `vector.transpose` and `vector.shape_cast` are semantically equivalent. A transformation that handles only `vector.transpose` is simply missing equivalent cases. This PR doesn’t make such transformations more or less correct - it only exposes unhandled but valid cases.

Ultimately, this PR is about agreeing on _the canonical form_. My view remains that operations not requiring data movement should canonicalise to `vector.shape_cast`, which helps solidify its semantics and keeps the model consistent. However, in the absence of a clear technical criterion (“energy function”) for preferring one form over another, much of this comes down to preference.

Both Diego and I support this change, but there is still disagreement on whether it qualifies as canonical (***). @ftynse 's talk on “Normal Forms for MLIR” from last week (****) offers a promising direction, but we’ll likely need to wait for Alex to implement it and propose an RFC. While that means progress here may pause for now, this discussion has helped clarify the underlying principles.

Thank you for the discussion and for all the input. If I missed or misinterpreted something, please post a clarification.

HTH

-Andrzej

(\*) Mahesh offered to share an example, so I may revisit this point.
(\*\*) This PR is deliberately limited in scope and only covers straightforward cases.
(\*\*\*) We could still land it as a non-canononicalisation.
(\*\*\*\*) Video should be available soon.

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


More information about the Mlir-commits mailing list