diff options
author | Yang Bai <baiyang0132@gmail.com> | 2025-06-19 00:26:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-18 09:26:04 -0700 |
commit | fe3933da15b5bc635bce156f1f8d11a784316a07 (patch) | |
tree | 3d523d6ea6d86c0ce2074db43b042a89f8c78b97 /llvm/lib/CodeGen/MachineFunction.cpp | |
parent | 00189211486d052b25429f11790ef5486cf9d3ce (diff) | |
download | llvm-fe3933da15b5bc635bce156f1f8d11a784316a07.zip llvm-fe3933da15b5bc635bce156f1f8d11a784316a07.tar.gz llvm-fe3933da15b5bc635bce156f1f8d11a784316a07.tar.bz2 |
[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@nvidia.com>
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
0 files changed, 0 insertions, 0 deletions