summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
AgeCommit message (Collapse)Author
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-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-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-08-31[MLIR] Apply clang-tidy fixes for readability-container-size-empty in ↵Mehdi Amini
VectorTransforms.cpp (NFC)
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-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-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-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-11[mlir][Vector] Do not propagate vector.extract on dynamic position (#148245)Kunwar Grover
Propagating vector.extract when a dynamic position is present can cause dominance issues and needs better handling. For now, disable propagation if there is a dynamic position present.
2025-07-02[mlir][vector][nfc] Rename ↵Andrzej Warzyński
`populateVectorTransferCollapseInnerMostContiguousDimsPatterns` (#145228) Renames `populateVectorTransferCollapseInnerMostContiguousDimsPatterns` as `populateDropInnerMostUnitDimsXferOpPatterns` + updates the corresponding comments. This addresses a TODO and makes the difference between these two `populate*` methods clearer: * `populateDropUnitDimWithShapeCastPatterns`, * `populateDropInnerMostUnitDimsXferOpPatterns`.
2025-05-27[mlir][vector] Update `CombineContractBroadcastMask` (#140050)Andrzej Warzyński
This patch updates `CombineContractBroadcastMask` to inherit from `MaskableOpRewritePattern`, enabling it to handle masked `vector.contract` operations. The pattern rewrites: ```mlir %a = vector.broadcast %a_bc %res vector.contract %a_bc, %b, ... ``` into: ```mlir // Move the broadcast into vector.contract (by updating the indexing // maps) %res vector.contract %a, %b, ... ``` The main challenge is supporting cases where the pattern drops a leading unit dimension. For example: ```mlir func.func @contract_broadcast_unit_dim_reduction_masked( %arg0 : vector<8x4xi32>, %arg1 : vector<8x4xi32>, %arg2 : vector<8x8xi32>, %mask: vector<1x8x8x4xi1>) -> vector<8x8xi32> { %0 = vector.broadcast %arg0 : vector<8x4xi32> to vector<1x8x4xi32> %1 = vector.broadcast %arg1 : vector<8x4xi32> to vector<1x8x4xi32> %result = vector.mask %mask { vector.contract { indexing_maps = [#map0, #map1, #map2], iterator_types = ["reduction", "parallel", "parallel", "reduction"], kind = #vector.kind<add> } %0, %1, %arg2 : vector<1x8x4xi32>, vector<1x8x4xi32> into vector<8x8xi32> } : vector<1x8x8x4xi1> -> vector<8x8xi32> return %result : vector<8x8xi32> } ``` Here, the leading unit dimension is dropped. To handle this, the mask is cast to the correct shape using a `vector.shape_cast`: ```mlir func.func @contract_broadcast_unit_dim_reduction_masked( %arg0: vector<8x4xi32>, %arg1: vector<8x4xi32>, %arg2: vector<8x8xi32>, %arg3: vector<1x8x8x4xi1>) -> vector<8x8xi32> { %mask_sc = vector.shape_cast %arg3 : vector<1x8x8x4xi1> to vector<8x8x4xi1> %res = vector.mask %mask_sc { vector.contract { indexing_maps = [#map, #map1, #map2], iterator_types = ["parallel", "parallel", "reduction"], kind = #vector.kind<add> } %arg0, %arg1, %mask_sc : vector<8x4xi32>, vector<8x4xi32> into vector<8x8xi32> } : vector<8x8x4xi1> -> vector<8x8xi32> return %res : vector<8x8xi32> } ``` While this isn't ideal - since it introduces a `vector.shape_cast` that must be cleaned up later - it reflects the best we can do once the input reaches `CombineContractBroadcastMask`. A more robust solution may involve simplifying the input earlier. I am leaving that as a TODO for myself to explore this further. Posting this now to unblock downstream work. LIMITATIONS Currently, this pattern assumes: * Only leading dimensions are dropped in the mask. * All dropped dimensions must be unit-sized.
2025-05-20[mlir][NFC] Simplify constant checks with isOneInteger and renamed ↵Han-Chung Wang
isZeroInteger. (#139340) The revision adds isOneInteger helper, and simplifies the existing code with the two methods. It removes some lambda, which makes code cleaner. For downstream users, you can update the code with the below script. ```bash sed -i "s/isZeroIndex/isZeroInteger/g" **/*.h sed -i "s/isZeroIndex/isZeroInteger/g" **/*.cpp ``` --------- Signed-off-by: hanhanW <hanhan0912@gmail.com>
2025-05-12[mlir][vector] Standardize `base` Naming Across Vector Ops (NFC) (#137859)Andrzej Warzyński
[mlir][vector] Standardize base Naming Across Vector Ops (NFC) This change standardizes the naming convention for the argument representing the value to read from or write to in Vector ops that interface with Tensors or MemRefs. Specifically, it ensures that all such ops use the name `base` (i.e., the base address or location to which offsets are applied). Updated operations: * `vector.transfer_read`, * `vector.transfer_write`. For reference, these ops already use `base`: * `vector.load`, `vector.store`, `vector.scatter`, `vector.gather`, `vector.expandload`, `vector.compressstore`, `vector.maskedstore`, `vector.maskedload`. This is a non-functional change (NFC) and does not alter the semantics of these operations. However, it does require users of the XFer ops to switch from `op.getSource()` to `op.getBase()`. To ease the transition, this PR temporarily adds a `getSource()` interface method for compatibility. This is intended for downstream use only and should not be relied on upstream. The method will be removed prior to the LLVM 21 release. Implements #131602
2025-04-22[mlir][vector] Sink vector.extract/splat into load/store ops (#134389)Ivan Butygin
``` vector.load %arg0[%arg1] : memref<?xf32>, vector<4xf32> vector.extract %0[1] : f32 from vector<4xf32> ``` Gets converted to: ``` %c1 = arith.constant 1 : index %0 = arith.addi %arg1, %c1 overflow<nsw> : index %1 = memref.load %arg0[%0] : memref<?xf32> ``` ``` %0 = vector.splat %arg2 : vector<1xf32> vector.store %0, %arg0[%arg1] : memref<?xf32>, vector<1xf32> ``` Gets converted to: ``` memref.store %arg2, %arg0[%arg1] : memref<?xf32> ```
2025-04-16[mlir][vector] Remove redundant shape_cast(shape_cast(x)) pattern (#135447)James Newling
This PR removes one OpRewritePattern `shape_cast(shape_cast(x)) -> x` that is already handled by `ShapeCastOp::fold`. Note that this might affect downstream users who indirectly call `populateShapeCastFoldingPatterns(RewritePatternSet &patterns, PatternBenefit)` and then use `patterns` with a `GreedyRewriteConfig config` that has `config.fold = false`. (only user I've checked is IREE, that never uses config.fold = false).
2025-04-07[mlir][vector] Standardise `valueToStore` Naming Across Vector Ops (NFC) ↵Andrzej Warzyński
(#134206) This change standardises the naming convention for the argument representing the value to store in various vector operations. Specifically, it ensures that all vector ops storing a value—whether into memory, a tensor, or another vector — use `valueToStore` for the corresponding argument name. Updated operations: * `vector.transfer_write`, `vector.insert`, `vector.scalable_insert`, `vector.insert_strided_slice`. For reference, here are operations that currently use `valueToStore`: * `vector.store` `vector.scatter`, `vector.compressstore`, `vector.maskedstore`. This change is non-functional (NFC) and does not affect the functionality of these operations. Implements #131602
2025-03-25[mlir][vector] Propagate `vector.extract` through elementwise ops (#131462)Ivan Butygin
Propagate `Extract(Elementwise(...))` -> `Elemetwise(Extract...)`. Currenly limited to the case when extract is the single use of elementwise to avoid introducing additional elementwise ops.
2025-02-14[MLIR][NFC] Return MemRefType in memref.subview return type inference ↵Tomás Longeri
functions (#120024) Avoids the need for cast, and matches the extra build functions, which take a `MemRefType`
2025-01-29Fix typo "tranpose" (#124929)Jay Foad
2025-01-24[mlir][vector] Disable `BreakDownVectorBitCast` for scalable vectors (#122725)Andrzej Warzyński
`BreakDownVectorBitCast` leverages * `vector.extract_strided_slices` + `vector.insert_strided_slices` As these Ops do not support extracting scalable sub-vectors (i.e. extracting/inserting a fraction of a scalable dim), it's best to bail out.
2025-01-21[mlir][NFC] Avoid using braced initializer lists to call a constructor. ↵Han-Chung Wang
(#123714) In the LLVM style guide, we prefer not using braced initializer lists to call a constructor. Also, we prefer using an equal before the open curly brace if we use a braced initializer list when initializing a variable. See https://llvm.org/docs/CodingStandards.html#do-not-use-braced-initializer-lists-to-call-a-constructor for more details. The style guide does not explain the reason well. There is an article from abseil, which mentions few benefits. E.g., we can avoid the most vexing parse, etc. See https://abseil.io/tips/88 for more details. Signed-off-by: hanhanW <hanhan0912@gmail.com>
2025-01-21[mlir][IR][NFC] Move free-standing functions to `MemRefType` (#123465)Matthias Springer
Turn free-standing `MemRefType`-related helper functions in `BuiltinTypes.h` into member functions.
2024-12-18[MemRef] Migrate away from PointerUnion::{is,get} (NFC) (#120382)Kazu Hirata
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
2024-11-18[MLIR] Fix `BubbleDownVectorBitCastForExtract` crash on non-static index ↵lialan
(#116518) Previously the patch was not expecting to handle non-static index, when the index is a non constant value it will crash. This patch is to make sure it return gracefully instead of crashing.
2024-10-01[mlir][vector] Add a new TD Op for patterns leveraging ShapeCastOp (#110525)Andrzej Warzyński
Adds a new Transform Dialect Op that collects patters for dropping unit dims from various Ops: * `transform.apply_patterns.vector.drop_unit_dims_with_shape_cast`. It excludes patterns for vector.transfer Ops - these are collected under: * `apply_patterns.vector.rank_reducing_subview_patterns`, and use ShapeCastOp _and_ SubviewOp to reduce the rank (and to eliminate unit dims). This new TD Ops allows us to test the "ShapeCast folder" pattern in isolation. I've extracted the only test that I could find for that folder from "vector-transforms.mlir" and moved it to a dedicated file: "shape-cast-folder.mlir". I also added a test case with scalable vectors. Changes in VectorTransforms.cpp are not needed (added a comment with a TODO + ordered the patterns alphabetically). I am Including them here to avoid a separate PR.
2024-09-27[mlir][vector] Add pattern for dropping unit dims from for loops (#109585)Quinn Dawkins
This adds a pattern for dropping unit dims from the iter_args of scf.for ops using vector.shape_cast. This composes with the other patterns for dropping unit dims from elementwise ops and transposes.
2024-08-16[mlir][vector] Group re-order patterns together (#102856)Andrzej Warzyński
Group all patterns that re-order vector.transpose and vector.broadcast Ops (*) under `populateSinkVectorOpsPatterns`. These patterns are normally used to "sink" redundant Vector Ops, hence grouping together. Example: ```mlir %at = vector.transpose %a, [1, 0]: vector<4x2xf32> to vector<2x4xf32> %bt = vector.transpose %b, [1, 0]: vector<4x2xf32> to vector<2x4xf32> %r = arith.addf %at, %bt : vector<2x4xf32> ``` would get converted to: ```mlir %0 = arith.addf %a, %b : vector<4x2xf32> %r = vector.transpose %0, [1, 0] : vector<2x4xf32> ``` This patch also moves all tests for these patterns so that all of them are: * run under one test-flag: `test-vector-sink-patterns`, * located in one file: "vector-sink.mlir". To facilitate this change: * `-test-sink-vector-broadcast` is renamed as `test-vector-sink-patterns`, * "sink-vector-broadcast.mlir" is renamed as "vector-sink.mlir", * tests for `ReorderCastOpsOnBroadcast` and `ReorderElementwiseOpsOnTranspose` patterns are moved from "vector-reduce-to-contract.mlir" to "vector-sink.mlir", * `ReorderElementwiseOpsOnTranspose` patterns are removed from `populateVectorReductionToContractPatterns` and added to (newly created) `populateSinkVectorOpsPatterns`, * `ReorderCastOpsOnBroadcast` patterns are removed from `populateVectorReductionToContractPatterns` - these are already present in `populateSinkVectorOpsPatterns`. This should allow us better layering and more straightforward testing. For the latter, the goal is to be able to easily identify which pattern a particular test is exercising (especially when it's a specific pattern). NOTES FOR DOWNSTREAM USERS In order to preserve the current functionality, please make sure to add * `populateSinkVectorOpsPatterns`, wherever you are using `populateVectorReductionToContractPatterns`. Also, rename `populateSinkVectorBroadcastPatterns` as `populateSinkVectorOpsPatterns`. (*) I didn't notice any other re-order patterns.
2024-08-14[mlir][vector] Add tests for `populateSinkVectorBroadcastPatterns` (1/n) ↵Andrzej Warzyński
(#102286) Adds tests for scalable vectors in: * sink-vector-broadcast.mlir This test file excercises patterns grouped under `populateSinkVectorBroadcastPatterns`, which includes: * `ReorderElementwiseOpsOnBroadcast`, * `ReorderCastOpsOnBroadcast`. Right now there are only tests for the former. However, I've noticed that "vector-reduce-to-contract.mlir" contains tests for the latter and I've left a few TODOs to group these tests back together in one file. Additionally, added some helpful `notifyMatchFailure` messages in `ReorderElementwiseOpsOnBroadcast`.
2024-08-08[mlir][vector] Handle corner cases in DropUnitDimsFromTransposeOp. (#102518)Han-Chung Wang
https://github.com/llvm/llvm-project/commit/da8778e499d8049ac68c2e152941a38ff2bc9fb2 breaks the lowering of vector.transpose that all the dimensions are unit dimensions. The revision fixes the issue and adds a test. --------- Signed-off-by: hanhanW <hanhan0912@gmail.com>
2024-08-08[mlir][vector] Fix return of `DropUnitDimsFromTransposeOp` pattern (#102478)Benjamin Maxwell
This accidentally returned `failure()` (rather than `success()`) when it applied.
2024-08-08[mlir][vector] Add pattern to drop unit dims from vector.transpose (#102017)Benjamin Maxwell
Example: BEFORE: ```mlir %transpose = vector.transpose %vector, [3, 0, 1, 2] : vector<1x1x4x[4]xf32> to vector<[4]x1x1x4xf32> ``` AFTER: ```mlir %dropDims = vector.shape_cast %vector : vector<1x1x4x[4]xf32> to vector<4x[4]xf32> %transpose = vector.transpose %0, [1, 0] : vector<4x[4]xf32> to vector<[4]x4xf32> %restoreDims = vector.shape_cast %transpose : vector<[4]x4xf32> to vector<[4]x1x1x4xf32> ```
2024-07-24[mlir][vector][nfc] Simplify `in_bounds` attr update (#100334)Andrzej Warzyński
Since the `in_bounds` attribute is mandatory, there's no need for logic like this (`readOp.getInBounds()` is guaranteed to return a non-empty ArrayRef): ```cpp ArrayAttr inBoundsAttr = readOp.getInBounds() ? rewriter.getArrayAttr( readOp.getInBoundsAttr().getValue().drop_back(dimsToDrop)) : ArrayAttr(); ``` Instead, we can do this: ```cpp ArrayAttr inBoundsAttr = rewriter.getArrayAttr( readOp.getInBoundsAttr().getValue().drop_back(dimsToDrop)); ``` This is a small follow-up for #97049 - this change should've been included there.
2024-07-17[MLIR][Vector] Generalize DropUnitDimFromElementwiseOps to non leading / ↵Hugo Trachino
trailing dimensions. (#98455) Generalizes DropUnitDimFromElementwiseOps to support inner unit dimensions. This change stems from improving lowering of contractionOps for Arm SME. Where we end up with inner unit dimensions on MulOp, BroadcastOp and TransposeOp, preventing the generation of outerproducts. discussed [here](https://discourse.llvm.org/t/on-improving-arm-sme-lowering-resilience-in-mlir/78543/17?u=nujaa). Fix after : https://github.com/llvm/llvm-project/pull/97652 showed an unhandled edge case when all dimensions are one. The generated target VectorType would be `vector<f32>` which is apparently not supported by the mulf. In case all dimensions are dropped, the target vectorType is vector<1xf32> --------- Co-authored-by: Benjamin Maxwell <macdue@dueutil.tech>
2024-07-12[mlir][vector] Restrict DropInnerMostUnitDimsTransfer{Read|Write} (#96218)Andrzej Warzyński
Restrict `DropInnerMostUnitDimsTransfer{Read|Write}` so that it fails when one of the indices to be dropped could be != 0 and "out of bounds": ```mlir func.func @negative_example(%arg0: memref<16x1xf32>, %arg1: vector<8x1xf32>, %idx_1: index, %idx_2: index) { vector.transfer_write %arg1, %arg0[%idx_1, %idx_2] {in_bounds = [true, false]} : vector<8x1xf32>, memref<16x1xf32> return } ``` This is an edge case that could represent an out-of-bounds access, though that will depend on the actual value of %i. Importantly, without this change it would be transformed as follows: ```mlir func.func @negative_example(%arg0: memref<16x1xf32>, %arg1: vector<8x1xf32>, %arg2: index, %arg3: index) { %subview = memref.subview %arg0[0, 0] [16, 1] [1, 1] : memref<16x1xf32> to memref<16xf32, strided<[1]>> %0 = vector.shape_cast %arg1 : vector<8x1xf32> to vector<8xf32> vector.transfer_write %0, %subview[%arg2] {in_bounds = [true]} : vector<8xf32>, memref<16xf32, strided<[1]>> return } ``` This is incorrect - `%idx_2` is ignored and the "out of bounds" flags is not propagated. Hence the extra restriction to avoid such cases. NOTE: This is a follow-up for: #94904
2024-07-03Revert "[MLIR][Vector] Generalize DropUnitDimFromElementwiseOps to non ↵Han-Chung Wang
leading / trailing dimensions." (#97652) Reverts llvm/llvm-project#92934 because it breaks some lowering. To repro: `mlir-opt -test-vector-transfer-flatten-patterns ~/repro.mlir` ```mlir func.func @unit_dim_folding(%arg0: vector<1x1xf32>) -> vector<1x1xf32> { %cst = arith.constant dense<0.000000e+00> : vector<1x1xf32> %0 = arith.mulf %arg0, %cst : vector<1x1xf32> return %0 : vector<1x1xf32> } ```
2024-07-02mlir/LogicalResult: move into llvm (#97309)Ramkumar Ramachandra
This patch is part of a project to move the Presburger library into LLVM.
2024-06-25[mlir][vector] Generalize folding of ext-contractionOp to other types. (#96593)Stanley Winata
Many state of the art models and quantization operations are now directly working on vector.contract on integers. This commit enables generalizes ext-contraction folding S.T we can emit more performant vector.contracts on codegen pipelines. Signed-off-by: Stanley Winata <stanley.winata@amd.com>
2024-06-21[mlir][vector] Add ElementwiseToOuterproduct (#93664)Hugo Trachino
1D multi-reduction are lowered to arith which can prevent some optimisations. I propose `ElementwiseToOuterproduct` matching a series of ops to generate `vector.outerproduct`. As part of some `ElementwiseToVectorOpsPatterns`, it could allow to fuse other elementwiseOps to vector dialect. Originally discussed https://discourse.llvm.org/t/on-improving-arm-sme-lowering-resilience-in-mlir/78543/24. quote @MacDue ``` %lhsBcast = vector.broadcast %lhsCast : vector<[4]xf32> to vector<[4]x[4]xf32> %lhsT = vector.transpose %lhsBcast, [1, 0] : vector<[4]x[4]xf32> to vector<[4]x[4]xf32> %rhsBcast = vector.broadcast %rhs : vector<[4]xf32> to vector<[4]x[4]xf32> %mul = arith.mulf %lhsT, %rhsBcast : vector<[4]x[4]xf32> ``` Can be rewritten as: ``` %mul = vector.outerproduct $lhs, $rhs : vector<[4]xf32>, vector<[4]xf32> ``` --------- Co-authored-by: Han-Chung Wang <hanhan0912@gmail.com>
2024-06-20[mlir][vector] Update tests for collapse 3/n (nfc) (#94906)Andrzej Warzyński
The main goal of this PR (and subsequent PRs), is to add more tests with scalable vectors to: * vector-transfer-collapse-inner-most-dims.mlir There's quite a few cases to consider, hence this is split into multiple PRs. In this PR, the very first test for `vector.transfer_write` is complemented with all the possible combinations: * scalable (rather than fixed) unit trailing dim, * dynamic (rather than static) trailing dim in the source memref. To this end, the following tests: * `@leading_scalable_dimension_transfer_write` `@trailing_scalable_one_dim_transfer_write` are replaced with: * `@drop_two_inner_most_dim_scalable_inner_dim` and `@negative_scalable_unit_dim`, respectively. In addition: * "_for_transfer_write" is removed from function names (to reduce noise). In addition, to maintain consistency between the tests for `xfer_read` and `xfer_write`, 2 negative tests for `xfer_read` are also renamed. This is to follow the suggestion made during the review of this PR. Extra comments in "VectorTransforms.cpp" are added to better document the limitations related to scalable vectors and which tests added here excercise. This is a follow-up for: #94490 and #94604 NOTE: This PR is limited to tests for `vector.transfer_write`.
2024-06-20[MLIR][Vector] Generalize DropUnitDimFromElementwiseOps to non leading / ↵Hugo Trachino
trailing dimensions. (#92934) Generalizes `DropUnitDimFromElementwiseOps` to support inner unit dimensions. This change stems from improving lowering of contractionOps for Arm SME. Where we end up with inner unit dimensions on MulOp, BroadcastOp and TransposeOp, preventing the generation of outerproducts. discussed [here](https://discourse.llvm.org/t/on-improving-arm-sme-lowering-resilience-in-mlir/78543/17?u=nujaa). --------- Co-authored-by: Benjamin Maxwell <macdue@dueutil.tech>
2024-06-12[mlir][vector] Restrict DropInnerMostUnitDimsTransferRead (#94904)Andrzej Warzyński
Restrict `DropInnerMostUnitDimsTransferRead` so that it fails when one of the indices to be dropped could be != 0, e.g. ```mlir func.func @negative_example(%A: memref<16x1xf32>, %i:index, %j:index) -> (vector<8x1xf32>) { %f0 = arith.constant 0.0 : f32 %1 = vector.transfer_read %A[%i, %j], %f0 : memref<16x1xf32>, vector<8x1xf32> return %1 : vector<8x1xf32> } ``` This is an edge case that could represent an out-of-bounds access, though that will depend on the actual value of `%j`. Importantly, _without this change_ it would be transformed as follows: ```mlir func.func @negative_example(%arg0: memref<16x1xf32>, %arg1: index, %arg2: index) -> vector<8x1xf32> { %cst = arith.constant 0.000000e+00 : f32 %subview = memref.subview %arg0[0, 0] [16, 1] [1, 1] : memref<16x1xf32> to memref<16xf32, strided<[1]>> %0 = vector.transfer_read %subview[%arg1], %cst : memref<16xf32, strided<[1]>>, vector<8xf32> %1 = vector.shape_cast %0 : vector<8xf32> to vector<8x1xf32> return %1 : vector<8x1xf32> } ``` This is incorrect - `%arg2` is ignored. Hence the extra restriction to avoid such cases. NOTE: This PR is limited to tests for `vector.transfer_read`.
2024-05-17[mlir][vector] Fix scalability issues in drop innermost unit dims transfer ↵Benjamin Maxwell
patterns (#92402) Previously, these rewrites would drop scalable dimensions and treated `[1]` (scalable one dim) as a unit dimension. This patch propagates scalable dimensions and ensures `[1]` is not treated as a unit dimension.
2024-03-29[mlir][Vector] Fix crash in drop unit dims (#87104)Diego Caballero
An `arith.select` may have a scalar condition and true/false vector values.
2024-03-12[mlir][vector] Use inferRankReducedResultType for subview type inference. ↵Han-Chung Wang
(#84395) Fixes https://github.com/openxla/iree/issues/16475
2024-02-28[mlir][Vector] Support vector.insert in bubbling bitcast patterns (#82843)Diego Caballero
This PR is adds support for `vector.insert` to the patterns that bubble up and down `vector.bitcat` ops across `vector.extract/extract_slice/insert_slice` ops.
2024-02-14Reapply "[mlir][vector] Drop inner unit dims for transfer ops on dynamic ↵Diego Caballero
shapes." (#80712) (#81778) This reverts commit b4c7152eb4f7971c111e3e2f60b55892def58d5d. Downstream regression due to another issue that this PR exposes. We have identified the work-items to fix the new issue here: https://github.com/openxla/iree/issues/16406 Co-authored-by: Han-Chung Wang <hanchung@google.com>
2024-02-08[MLIR] Fix crash in AffineMap::replace for zero result maps (#80930)Uday Bondhugula
Fix obvious bug in AffineMap::replace for the case of zero result maps. Extend/complete inferExprsFromList to work with empty expression lists.
2024-02-05[mlir][vector] Drop inner unit dims for xWrite on dynamic shapes. (#80725)Han-Chung Wang
This is part of https://github.com/llvm/llvm-project/commit/66347e516e22f9159b86024071fb92f364ac4418 The regression in downstream projects is about transfer_read patterns, which needs more investigation. Add the support for transfer_write for now.