[all-commits] [llvm/llvm-project] fe3933: [mlir][vector] Support complete folding in single ...
Yang Bai via All-commits
all-commits at lists.llvm.org
Wed Jun 18 09:26:25 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: fe3933da15b5bc635bce156f1f8d11a784316a07
https://github.com/llvm/llvm-project/commit/fe3933da15b5bc635bce156f1f8d11a784316a07
Author: Yang Bai <baiyang0132 at gmail.com>
Date: 2025-06-18 (Wed, 18 Jun 2025)
Changed paths:
M mlir/lib/Dialect/Vector/IR/VectorOps.cpp
M mlir/test/Dialect/Affine/constant-fold.mlir
M mlir/test/Dialect/Linalg/mesh-spmdization.mlir
M mlir/test/Dialect/Mesh/spmdization.mlir
M mlir/test/Dialect/Tensor/mesh-spmdization.mlir
M mlir/test/Dialect/Tosa/constant_folding.mlir
M mlir/test/Dialect/Vector/constant-fold.mlir
A mlir/test/Dialect/Vector/single-fold.mlir
M mlir/test/Transforms/constant-fold-debuginfo.mlir
M mlir/test/Transforms/constant-fold.mlir
M mlir/test/lib/Transforms/CMakeLists.txt
R mlir/test/lib/Transforms/TestConstantFold.cpp
A mlir/test/lib/Transforms/TestSingleFold.cpp
M mlir/tools/mlir-opt/mlir-opt.cpp
Log Message:
-----------
[mlir][vector] Support complete folding in single pass for vector.insert/vector.extract (#142124)
### Description
This patch improves the folding efficiency of `vector.insert` and
`vector.extract` operations by not returning early after successfully
converting dynamic indices to static indices.
This PR also renames the test pass `TestConstantFold` to
`TestSingleFold` and adds comprehensive documentation explaining the
single-pass folding behavior.
### Motivation
Since the `OpBuilder::createOrFold` function only calls `fold` **once**,
the current `fold` methods of `vector.insert` and `vector.extract` may
leave the op in a state that can be folded further. For example,
consider the following un-folded IR:
```
%v1 = vector.insert %e1, %v0 [0] : f32 into vector<128xf32>
%c0 = arith.constant 0 : index
%e2 = vector.extract %v1[%c0] : f32 from vector<128xf32>
```
If we use `createOrFold` to create the `vector.extract` op, then the
result will be:
```
%v1 = vector.insert %e1, %v0 [127] : f32 into vector<128xf32>
%e2 = vector.extract %v1[0] : f32 from vector<128xf32>
```
But this is not the optimal result. `createOrFold` should have returned
`%e1`.
The reason is that the execution of fold returns immediately after
`extractInsertFoldConstantOp`, causing subsequent folding logics to be
skipped.
---------
Co-authored-by: Yang Bai <yangb at nvidia.com>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list