summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/Vector/Transforms
AgeCommit message (Collapse)Author
2025-11-20[mlir][Vector] Add support for scalable vectors to `ScanToArithOps` (#123117)Andrzej Warzyński
Note, scalable reductions dims are left as a TODO.
2025-11-19[MLIR][Vector] Add unroll pattern for vector.shape_cast (#167738)Nishant Patel
This PR adds pattern for unrolling shape_cast given a targetShape. This PR is a follow up of #164010 which was very general and was using inserts and extracts on each element (which is also LowerVectorShapeCast.cpp is doing). After doing some more research on use cases, we (me and @Jianhui-Li ) realized that the previous version in #164010 is unnecessarily generic and doesn't fit our performance needs. Our use case requires that targetShape is contiguous in both source and result vector. This pattern only applies when contiguous slices can be extracted from the source vector and inserted into the result vector such that each slice remains in vector form with targetShape (and not decompose to scalars). In these cases, the unrolling proceeds as: vector.extract_strided_slice -> vector.shape_cast (on the slice unrolled) -> vector.insert_strided_slice
2025-11-14[MLIR] Extend vector.scatter to accept tensor as base (#165548)Ryutaro Okada
This PR makes the following improvements to `vector.scatter` and its lowering pipeline: - In addition to `memref`, accept a ranked `tensor` as the base operand of `vector.scatter`, similar to `vector.transfer_write`. - Implement bufferization support for `vector.scatter`, so that tensor-based scatter ops can be fully lowered to memref-based forms. It's worth to complete the functionality of map_scatter decomposition. Full discussion can be found here: https://github.com/iree-org/iree/issues/21135 --------- Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-10-22[mlir][vector][xegpu] Accept uniform values in `getDistributedType` (#163887)Charitha Saumya
Uniform values should not be distributed during vector distribution. Example would be a reduction result where reduction happens across lanes. However, current `getDistributedType` does not accept a zero result affine map (i.e. no distributed dims) when describing the distributed dimensions. This result in null type being returned and crashing the vector distribution in some cases. An example case would be a `scf.for` op (about to be distributed) in which one of the for result is a uniform value and it does not have a user outside the warp op. This necessitates querying the `getDistributedType` to figure our the distributed type of this value.
2025-10-22[mlir] Switch uses of deprecated .create methods to free function. NFC. ↵Jakub Kuderski
(#164635) See https://discourse.llvm.org/t/psa-opty-create-now-with-100-more-tab-complete/87339.
2025-10-17[mlir][Vector] Pattern to linearize broadcast (#163845)James Newling
The PR https://github.com/llvm/llvm-project/pull/162167 removed a pattern to linearize vector.splat, without adding the equivalent pattern for vector.broadcast. This PR adds such a pattern, hopefully brining vector.broadcast up to full parity with vector.splat that has now been removed. --------- Signed-off-by: James Newling <james.newling@gmail.com>
2025-10-17[mlir][vector] Add support for yielding loop bounds in `scf.for` ↵Charitha Saumya
distribution. (#163443) In some cases, loop bounds (lower, upper and step) of `scf.for` can come locally from the parent warp op the `scf.for`. Current logic will not yield the loop bounds in the new warp op generated during lowering causing sinked `scf.for` to have non dominating use. In this PR, we have added logic to yield loop bounds by default (treat them as other operands of `scf.for`) which fixes this bug.
2025-10-15[MLIR][Vector] Extend elementwise pattern to support unrolling from higher ↵Nishant Patel
rank to lower rank (#162515) This PR enhances the elementwise unrolling pattern to support higher rank to lower rank unroll. The approach is to add leading unit dims to lower rank targetShape to match the rank of original vector (because ExtractStridedSlice requires same rank to extractSlices), extract slice, reshape to targetShape's rank and perform the operation.
2025-10-15[MLIR][Vector] Improve warp distribution robustness (#161647)Artem Kroviakov
2025-10-11[mlir] Use llvm accumulate wrappers. NFCI. (#162957)Jakub Kuderski
Use wrappers around `std::accumulate` to make the code more concise and less bug-prone: https://github.com/llvm/llvm-project/pull/162129. With `std::accumulate`, it's the initial value that determines the accumulator type. `llvm::sum_of` and `llvm::product_of` pick the right accumulator type based on the range element type. Found some funny bugs like a local accumulate helper that calculated a sum with initial value of 1 -- we didn't hit the bug because the code was actually dead...
2025-10-10[MLIR][Vector] Remove vector.splat (#162167)James Newling
vector.splat has been deprecated (user: please use the very similar vector.broadcast instead) with the last PR landing about 6 weeks ago. The discourse discussion is at https://discourse.llvm.org/t/rfc-mlir-vector-deprecate-then-remove-vector-splat/87143/1 The last PR was #152230 This PR completely removes vector.splat. In addition to removing vector.splat from VectorOps.td, it - Updates the few remaining places where vector::SplatOp is created (now vector::BroadcastOp is created) - Removes temporary patterns where vector.splat is replaced by vector.broadcast The only place 'vector.splat' appears is now the files https://github.com/llvm/llvm-project/blob/main/mlir/utils/tree-sitter-mlir/test/corpus/op.txt and https://github.com/llvm/llvm-project/blob/main/mlir/utils/tree-sitter-mlir/dialect/vector.js --------- Signed-off-by: James Newling <james.newling@gmail.com>
2025-10-03[MLIR] Apply clang-tidy fixes for modernize-use-bool-literals in ↵Mehdi Amini
VectorEmulateNarrowType.cpp (NFC)
2025-10-02[mlir][vector] Simplify op rewrite pattern inheriting constructors. NFC. ↵Jakub Kuderski
(#161670) Use the `Base` type alias from https://github.com/llvm/llvm-project/pull/158433.
2025-09-29[MLIR][MemRef] Change builders with `int` alignment params to ↵jiang1997
`llvm::MaybeAlign` (#159449) Change remaining OpBuilder methods to use `llvm::MaybeAlign` instead of `uint64_t` for alignment parameters. --------- Co-authored-by: Erick Ochoa Lopez <erick.ochoalopez@amd.com>
2025-09-18[mlir] Move vector.{to_elements,from_elements} unrolling to ↵Erick Ochoa Lopez
`VectorUnroll.cpp` (#159118) This PR moves the patterns that unroll vector.to_elements and vector.from_elements into the file with other vector unrolling operations. This PR also adds these unrolling patterns into the `populateVectorUnrollPatterns`. And renames `populateVectorToElementsLoweringPatterns` `populateVectorFromElementsLoweringPatterns` to `populateVectorToElementsUnrollPatterns` `populateVectorFromElementsUnrollPatterns`.
2025-09-17[MLIR] Fix compilation after #157771 (#159257)Jan Patrick Lehr
The original PR broke pretty much all our bots. Apologies for the noise in the previous PR.
2025-09-16[mlir][Vector] Add patterns to lower `vector.shuffle` (#157611)Diego Caballero
This PR adds patterns to lower `vector.shuffle` with inputs with different vector sizes more efficiently. The current LLVM lowering for these cases degenerates to a sequence of `vector.extract` and `vector.insert` operations. With this PR, the smaller input is promoted to larger vector size by introducing an extra `vector.shuffle`.
2025-09-16[MLIR][Vector] Add unrolling pattern for vector StepOp (#157752)Nishant Patel
This PR adds unrolling pattern for vector.step op to VectorUnroll transform.
2025-09-16[MLIR] Make 1-D memref flattening a prerequisite for vector narrow type ↵Alan Li
emulation (#157771) Addresses: https://github.com/llvm/llvm-project/issues/115653 We already have utilities to flatten memrefs into 1-D. This change makes memref flattening a prerequisite for vector narrow type emulation, ensuring that emulation patterns only need to handle 1-D scenarios.
2025-09-15[mlir][vector] Use `source` as the source argument name (#158258)Andrzej Warzyński
This patch updates the following ops to use `source` (instead of `vector`) as the name for their source argument: * `vector.extract` * `vector.scalable.extract` * `vector.extract_strided_slice` This change ensures naming consistency with the "builders" for these Ops that already use the name `source` rather than `vector`. It also addresses part of: * https://github.com/llvm/llvm-project/issues/131602 Specifically, it ensures that we use `source` and `dest` for read and write operations, respectively (as opposed to `vector` and `dest`).
2025-09-11[mlir][vector] Add LinearizeVectorToElements (#157740)Erick Ochoa Lopez
Co-authored-by: James Newling <james.newling@gmail.com>
2025-09-11[mlir][vector] Add vector.to_elements unrolling (#157142)Erick Ochoa Lopez
This PR adds support for unrolling `vector.to_element`'s source operand. It transforms ```mlir %0:8 = vector.to_elements %v : vector<2x2x2xf32> ``` to ```mlir %v0 = vector.extract %v[0] : vector<2x2xf32> from vector<2x2x2xf32> %v1 = vector.extract %v[1] : vector<2x2xf32> from vector<2x2x2xf32> %0:4 = vector.to_elements %v0 : vector<2x2xf32> %1:4 = vector.to_elements %v1 : vector<2x2xf32> // %0:8 = %0:4 - %1:4 ``` This pattern will be applied until there are only 1-D vectors left. --------- Signed-off-by: hanhanW <hanhan0912@gmail.com> Co-authored-by: hanhanW <hanhan0912@gmail.com> Co-authored-by: Jakub Kuderski <kubakuderski@gmail.com>
2025-09-10[MLIR][Vector] Add warp distribution for `scf.if` (#157119)Artem Kroviakov
This PR adds `scf.if` op distribution to the existing `VectorDistribute` patterns. The logic mostly follows that of `scf.for`: move op outside, wrap each branch with `gpu.warp_execute_on_lane_0`. A notable difference to `scf.for` is that each branch has its own set of escaping values, and `scf.if` itself does not have block arguments.
2025-09-05[mlir][vector] Propagate alignment when emulating masked{load,stores}. (#155648)Erick Ochoa Lopez
Propagate alignment from `vector.maskedload` and `vector.maskedstore` to `memref.load` and `memref.store` during `VectorEmulateMaskedLoadStore` pass.
2025-09-05[mlir][vector] Propagate alignment in LowerVectorGather. (#155683)Erick Ochoa Lopez
Alignment is properly propagated when patterns `UnrollGather`, `RemoveStrideFromGatherSource`, or `Gather1DToConditionalLoads` are applied.
2025-09-03[MLIR] Add LDBG() tracing to VectorTransferOpTransforms.cpp (NFC)Mehdi Amini
Had to debug an issue, more debugging helped here.
2025-08-31[MLIR] Apply clang-tidy fixes for readability-container-size-empty in ↵Mehdi Amini
VectorTransforms.cpp (NFC)
2025-08-28[MLIR][Vector] Add warp distribution for `vector.step` op (#155425)Artem Kroviakov
This PR adds a distribution pattern for [`vector.step`](https://mlir.llvm.org/docs/Dialects/Vector/#vectorstep-vectorstepop) op. The result of the step op is a vector containing a sequence `[0,1,...,N-1]`. For the warp distribution, we consider a vector with `N == warp_size` (think SIMD). Distributing it to SIMT, means that each lane is represented by a thread/lane id scalar. More complex cases with the support for warp size multiples (e.g., `[0,1,...,2*N-1]`) require additional layout information to be handled properly. Such support may be added later. The lane id scalar is wrapped into a `vector<1xindex>` to emulate the sequence distribution result. Other than that, the distribution is similar to that of `arith.constant`.
2025-08-27[mlir][vector] Follow-up improvements for multi-dimensional ↵Yang Bai
vector.from_elements support (#154664) This PR is a follow-up to #151175 that supported lowering multi-dimensional `vector.from_elements` op to LLVM by introducing a unrolling pattern. ## Changes ### Add `vector.shape_cast` based flattening pattern for `vector.from_elements` This change introduces a new linearization pattern that uses `vector.shape_cast` to flatten multi-dimensional `vector.from_elements` operations. This provides an alternative approach to the unrolling-based method introduced in #151175. **Example:** ```mlir // Before %v = vector.from_elements %e0, %e1, %e2, %e3 : vector<2x2xf32> // After %flat = vector.from_elements %e0, %e1, %e2, %e3 : vector<4xf32> %result = vector.shape_cast %flat : vector<4xf32> to vector<2x2xf32> ``` --------- Co-authored-by: Yang Bai <yangb@nvidia.com> Co-authored-by: James Newling <james.newling@gmail.com>
2025-08-25[mlir][vector] Rename gather/scatter arguments (nfc) (#153640)Andrzej Warzyński
Renames `indices` as `offsets` and `index_vec` as `indices`. This is primarily to make clearer distinction between the arguments.
2025-08-22[mlir][gpu] Warp execute terminator getter (#154729)Adam Siemieniuk
Adds a utility getter to `warp_execute_on_lane_0` which simplifies access to the op's terminator. Uses are refactored to utilize the new terminator getter.
2025-08-21[mlir] add getViewDest method to viewLikeOpInterface (#154524)donald chen
The viewLikeOpInterface abstracts the behavior of an operation view one buffer as another. However, the current interface only includes a "getViewSource" method and lacks a "getViewDest" method. Previously, it was generally assumed that viewLikeOpInterface operations would have only one return value, which was the view dest. This assumption was broken by memref.extract_strided_metadata, and more operations may break these silent conventions in the future. Calling "viewLikeInterface->getResult(0)" may lead to a core dump at runtime. Therefore, we need 'getViewDest' method to standardize our behavior. This patch adds the getViewDest function to viewLikeOpInterface and modifies the usage points of viewLikeOpInterface to standardize its use.
2025-08-19[NFC][mlir][vector] Handle potential static cast assertion. (#152957)Md Asghar Ahmad Shahid
In FoldArithToVectorOuterProduct pattern, static cast to vector type causes assertion when a scalar type was encountered. It seems the author meant to have a dyn_cast instead. This NFC patch handles it by using dyn_cast.
2025-08-18[mlir][vector] Support multi-dimensional vectors in ↵Yang Bai
VectorFromElementsLowering (#151175) This patch introduces a new unrolling-based approach for lowering multi-dimensional `vector.from_elements` operations. **Implementation Details:** 1. **New Transform Pattern**: Added `UnrollFromElements` that unrolls a N-D(N>=2) from_elements op to a (N-1)-D from_elements op align the outermost dimension. 2. **Utility Functions**: Added `unrollVectorOp` to reuse the unroll algo of vector.gather for vector.from_elements. 3. **Integration**: Added the unrolling pattern to the convert-vector-to-llvm pass as a temporal transformation. 4. Use direct LLVM dialect operations instead of intermediate vector.insert operations for efficiency in `VectorFromElementsLowering`. **Example:** ```mlir // unroll %v = vector.from_elements %e0, %e1, %e2, %e3 : vector<2x2xf32> => %poison_2d = ub.poison : vector<2x2xf32> %vec_1d_0 = vector.from_elements %e0, %e1 : vector<2xf32> %vec_2d_0 = vector.insert %vec_1d_0, %poison_2d [0] : vector<2xf32> into vector<2x2xf32> %vec_1d_1 = vector.from_elements %e2, %e3 : vector<2xf32> %result = vector.insert %vec_1d_1, %vec_2d_0 [1] : vector<2xf32> into vector<2x2xf32> // convert-vector-to-llvm %v = vector.from_elements %e0, %e1, %e2, %e3 : vector<2x2xf32> => %poison_2d = ub.poison : vector<2x2xf32> %poison_2d_cast = builtin.unrealized_conversion_cast %poison_2d : vector<2x2xf32> to !llvm.array<2 x vector<2xf32>> %poison_1d_0 = llvm.mlir.poison : vector<2xf32> %c0_0 = llvm.mlir.constant(0 : i64) : i64 %vec_1d_0_0 = llvm.insertelement %e0, %poison_1d_0[%c0_0 : i64] : vector<2xf32> %c1_0 = llvm.mlir.constant(1 : i64) : i64 %vec_1d_0_1 = llvm.insertelement %e1, %vec_1d_0_0[%c1_0 : i64] : vector<2xf32> %vec_2d_0 = llvm.insertvalue %vec_1d_0_1, %poison_2d_cast[0] : !llvm.array<2 x vector<2xf32>> %poison_1d_1 = llvm.mlir.poison : vector<2xf32> %c0_1 = llvm.mlir.constant(0 : i64) : i64 %vec_1d_1_0 = llvm.insertelement %e2, %poison_1d_1[%c0_1 : i64] : vector<2xf32> %c1_1 = llvm.mlir.constant(1 : i64) : i64 %vec_1d_1_1 = llvm.insertelement %e3, %vec_1d_1_0[%c1_1 : i64] : vector<2xf32> %vec_2d_1 = llvm.insertvalue %vec_1d_1_1, %vec_2d_0[1] : !llvm.array<2 x vector<2xf32>> %result = builtin.unrealized_conversion_cast %vec_2d_1 : !llvm.array<2 x vector<2xf32>> to vector<2x2xf32> ``` --------- Co-authored-by: Nicolas Vasilache <Nico.Vasilache@amd.com> Co-authored-by: Yang Bai <yangb@nvidia.com> Co-authored-by: James Newling <james.newling@gmail.com> Co-authored-by: Diego Caballero <dieg0ca6aller0@gmail.com>
2025-08-15[mlir][SCF] `scf.for`: Add support for unsigned integer comparison (#153379)Matthias Springer
Add a new unit attribute to allow for unsigned integer comparison. Example: ```mlir scf.for unsigned %iv_32 = %lb_32 to %ub_32 step %step_32 : i32 { // body } ``` Discussion: https://discourse.llvm.org/t/scf-should-scf-for-support-unsigned-comparison/84655
2025-07-31[mlir][vector] Avoid use of vector.splat in transforms (#150279)James Newling
This is part of vector.splat deprecation Reference: https://discourse.llvm.org/t/rfc-mlir-vector-deprecate-then-remove-vector-splat/87143/5 Instead of creating vector::SplatOp, create vector::BroadcastOp
2025-07-30[mlir][Vector] Allow elementwise/broadcast swap to handle mixed types (#151274)Krzysztof Drewniak
This patch extends the operation that rewrites elementwise operations whose inputs are all broadcast from the same shape to handle mixed-types, such as when the result and input types don't match, or when the inputs have multiple types. PR #150867 failed to check for the possibility of type mismatches when rewriting splat constants. In order to fix that issue, we add support for mixed-type operations more generally.
2025-07-30[MLIR] Migrate some conversion passes and dialects to LDBG() macro (NFC) ↵Mehdi Amini
(#151349)
2025-07-29[mlir][Vector] Make elementwise-on-broadcast sinking handle splat consts ↵Krzysztof Drewniak
(#150867) There is a pattern that rewrites elementwise_op(broadcast(x1 : T to U), broadcast(x2 : T to U), ...) to broadcast(elementwise_op(x1, x2, ...) : T to U). This pattern did not, however, account for the case where a broadcast constant is represented as a SplatElementsAttr, which can safely be reshaped or scalarized but is not a `vector.broadcast` or `vector.splat` operation. This patch fixes this oversight, prenting premature broadcasting. This did result in the need to update some linalg dialect tests, which now feature a less-broadcast computation and/or more constant folding.
2025-07-25[mlir][NFC] update `mlir/Dialect` create APIs (32/n) (#150657)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-25[mlir] Switch to new LDBG macro (#150616)Jacques Pienaar
Change local variants to use new central one.
2025-07-25[mlir][vector] Add a check to ensure input vector rank equals target shape ↵Longsheng Mou
rank (#149239) The crash is caused because, during IR transformation, the vector-unrolling pass (using ExtractStridedSliceOp) attempts to slice an input vector of higher rank using a target vector of lower rank, which is not supported. Fixes #148368.
2025-07-23[mlir] Remove unused includes (NFC) (#150266)Kazu Hirata
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-07-22[mlir][NFC] update `mlir/Dialect` create APIs (24/n) (#149931)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-21[mlir][vector] Remove MatrixMultiplyOp and FlatTransposeOp from Vector ↵Andrzej Warzyński
dialect (#144307) This patch deletes `vector.matrix_multiply` and `vector.flat_transpose`, which are thin wrappers around the corresponding LLVM intrinsics: - `llvm.intr.matrix.multiply` - `llvm.intr.matrix.transpose` These Vector dialect ops did not provide additional semantics or abstraction beyond the LLVM intrinsics. Their removal simplifies the lowering pipeline without losing any functionality. The lowering chains: - `vector.contract` → `vector.matrix_multiply` → `llvm.intr.matrix.multiply` - `vector.transpose` → `vector.flat_transpose` → `llvm.intr.matrix.transpose` are now replaced with: - `vector.contract` → `llvm.intr.matrix.multiply` - `vector.transpose` → `llvm.intr.matrix.transpose` This was accomplished by directly replacing: - `vector::MatrixMultiplyOp` with `LLVM::MatrixMultiplyOp` - `vector::FlatTransposeOp` with `LLVM::MatrixTransposeOp` Note: To avoid a build-time dependency from `Vector` to `LLVM`, relevant transformations are moved from "Vector/Transforms" to `Conversion/VectorToLLVM`.
2025-07-14[mlir] Remove unused includes (NFC) (#148769)Kazu Hirata
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-07-14Reapply [mlir][vector] Refactor WarpOpScfForOp to support unused or swapped ↵Charitha Saumya
forOp results. (#148313) Reapply attempt for : https://github.com/llvm/llvm-project/pull/148291 Fix for the build failure reported in : https://lab.llvm.org/buildbot/#/builders/116/builds/15477 ----- This crash is caused by mismatch of distributed type returned by `getDistributedType` and intended distributed type for forOp results. Solution diff: https://github.com/llvm/llvm-project/commit/20c2cf67662c3b3fdecf95a0e280809f98d8db50 Example: ``` func.func @warp_scf_for_broadcasted_result(%arg0: index) -> vector<1xf32> { %c128 = arith.constant 128 : index %c1 = arith.constant 1 : index %c0 = arith.constant 0 : index %2 = gpu.warp_execute_on_lane_0(%arg0)[32] -> (vector<1xf32>) { %ini = "some_def"() : () -> (vector<1xf32>) %0 = scf.for %arg3 = %c0 to %c128 step %c1 iter_args(%arg4 = %ini) -> (vector<1xf32>) { %1 = "some_op"(%arg4) : (vector<1xf32>) -> (vector<1xf32>) scf.yield %1 : vector<1xf32> } gpu.yield %0 : vector<1xf32> } return %2 : vector<1xf32> } ``` In this case the distributed type for forOp result is `vector<1xf32>` (result is not distributed and broadcasted to all lanes instead). However, in this case `getDistributedType` will return NULL type. Therefore, if the distributed type can be recovered from warpOp, we should always do that first before using `getDistributedType`
2025-07-14[MLIR] [Vector] Linearization patterns for vector.load and vector.store ↵Nishant Patel
(#145115) This PR add inearizarion pattern for vector.load and vector.store. It is follow up PR to https://github.com/llvm/llvm-project/pull/143420#issuecomment-2967406606
2025-07-14[mlir][MemRef] Add support for emulating narrow floats (#148036)Quinn Dawkins
This enables memref.load/store + vector.load/store support for sub-byte float types. Since the memref types don't matter for loads/stores, we still use the same types as integers with equivalent widths, with a few extra bitcasts needed around certain operations. There is no direct change needed for vector.load/store support. The tests added for them are to verify that float types are supported as well.
2025-07-11[mlir][Vector] Support scalar `vector.extract` in VectorLinearize (#147440)Diego Caballero
It generates a linearized version of the `vector.extract` for scalar cases.