11 Commits

Author SHA1 Message Date
Jakub Kuderski
3960ff6ca0
[mlir][vector] Simplify op rewrite pattern inheriting constructors. NFC. (#161670)
Use the `Base` type alias from
https://github.com/llvm/llvm-project/pull/158433.
2025-10-02 19:07:25 -04:00
Maksim Levental
f904cdd6c3
[mlir][NFC] update mlir/Dialect create APIs (24/n) (#149931)
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-22 08:16:15 -04:00
James Newling
7ce315d14a
[mlir][vector] Improve shape_cast lowering (#140800)
Before this PR, a rank-m -> rank-n vector.shape_cast with m,n>1 was
lowered to extracts/inserts of single elements, so that a shape_cast on
a vector with N elements would always require N extracts/inserts. While
this is necessary in the worst case scenario it is sometimes possible to
use fewer, larger extracts/inserts. Specifically, the largest common
suffix on the shapes of the source and result can be extracted/inserted.
For example:

```mlir
%0 = vector.shape_cast %arg0 : vector<10x2x3xf32> to vector<2x5x2x3xf32>
```

has common suffix of shape `2x3`. Before this PR, this would be lowered
to 60 extract/insert pairs with extracts of the form
`vector.extract %arg0 [a, b, c] : f32 from vector<10x2x3xf32>`. With
this PR it is 10 extract/insert pairs with extracts of the form
`vector.extract %arg0 [a] : vector<2x3xf32> from vector<10x2x3xf32>`.
2025-06-05 10:18:38 -07:00
Kunwar Grover
dc28e0d5d2
[mlir][Vector] Remove more special case uses for extractelement/insertelement (#130166)
A number of places in our codebase special case to use
extractelement/insertelement for 0D vectors, because extract/insert did
not support 0D vectors previously. Since insert/extract support 0D
vectors now, use them instead of special casing.
2025-03-24 13:04:16 +00:00
Diego Caballero
5a0075adbb
[mlir][Vector] Generate poison vectors in vector.shape_cast lowering (#125613)
This is the first PR that introduces `ub.poison` vectors as part of a
rewrite/conversion pattern in the Vector dialect. It replaces the
`arith.constant dense<0>` vector initialization for
`vector.insert_slice` ops with a poison vector.

This PR depends on all the previous PRs that introduced support for
poison in Vector operations such as `vector.shuffle`, `vector.extract`,
`vector.insert`, including ODS, canonicalization and lowering support.

This PR may improve end-to-end compilation time through LLVM, depending
on the workloads.
2025-02-07 10:42:55 -08:00
Diego Caballero
a7a4c16c67
[mlir][Vector] Support efficient shape cast lowering for n-D vectors (#123497)
This PR implements a generalization of the existing more efficient
lowering of shape casts from 2-D to 1D and 1-D to 2-D vectors. This
significantly reduces code size and generates more performant code for
n-D shape casts that make their way to LLVM/SPIR-V.
2025-01-27 14:36:19 -08:00
Ramkumar Ramachandra
db791b278a
mlir/LogicalResult: move into llvm (#97309)
This patch is part of a project to move the Presburger library into
LLVM.
2024-07-02 10:42:33 +01:00
Cullen Rhodes
9816edc9f3
[mlir][vector] add result type to vector.extract assembly format (#66499)
The vector.extract assembly format currently only contains the source
type, for example:

  %1 = vector.extract %0[1] : vector<3x7x8xf32>

it's not immediately obvious if this is the source or result type. This
patch improves the assembly format to make this clearer, so the above
becomes:

  %1 = vector.extract %0[1] : vector<7x8xf32> from vector<3x7x8xf32>
2023-09-28 11:11:16 +01:00
Benjamin Maxwell
8dffb71cba [mlir][VectorOps] Add lowering for vector.shape_cast of scalable vectors
This adds a lowering similar to the general shape_cast lowering, but
instead moves elements a (scalable) subvector at a time via
vector.scalable.extract/insert. It is restricted to the case where both
the source and result vector types have a single trailing scalable
dimension (due to limitations of the insert/extract ops).

The current lowerings are now disabled for scalable vectors, as they
produce incorrect results at runtime (due to assuming a fixed number
of elements).

Examples of casts that now work:

  // Flattening:
  %v = vector.shape_cast %arg0 : vector<4x[8]xi8> to vector<[32]xi8>

  // Un-flattening:
  %v = vector.shape_cast %arg0 : vector<[8]xi32> to vector<2x1x[4]xi32>

Reviewed By: awarzynski, nicolasvasilache

Differential Revision: https://reviews.llvm.org/D159217
2023-09-07 15:58:44 +00:00
Diego Caballero
0935c0556b [mlir][Vector] Add support for 0-D 'vector.shape_cast' lowering
This PR adds support for shape casting from and to 0-D vectors.

Reviewed By: nicolasvasilache, hanchung, awarzynski

Differential Revision: https://reviews.llvm.org/D151851
2023-06-01 22:22:16 +00:00
Nicolas Vasilache
2bc4c3e920 [mlir][Vector] NFC - Reorganize vector patterns
Vector dialect patterns have grown enormously in the past year to a point where they are now impenetrable.
Start reorganizing them towards finer-grained control.

Differential Revision: https://reviews.llvm.org/D146736
2023-03-23 11:30:25 -07:00