[Mlir-commits] [mlir] [mlir][Vector] Add `vector.to_elements` op (PR #141457)
Kunwar Grover
llvmlistbot at llvm.org
Mon May 26 07:39:02 PDT 2025
================
@@ -789,6 +789,57 @@ def Vector_FMAOp :
}];
}
+def Vector_ToElementsOp : Vector_Op<"to_elements", [
+ Pure,
+ TypesMatchWith<"operand element type matches result types",
+ "input", "elements", "SmallVector<Type>("
+ "::llvm::cast<VectorType>($_self).getNumElements(), "
+ "::llvm::cast<VectorType>($_self).getElementType())">]> {
+ let summary = "operation that decomposes a vector into all its scalar elements";
+ let description = [{
+ This operation decomposes all the scalar elements from a vector. The
+ decomposed scalar elements are returned in row-major order. The number of
+ scalar results must match the number of elements in the input vector type.
+ All the result elements have the same result type, which must match the
+ element type of the input vector. Scalable vectors are not supported.
----------------
Groverkss wrote:
Is it important that it decomposes into all elements? This op could be really useful for unrolling a dimension if we could do it dimwise. Something like:
```
%0:16 = vector.to_elements %v : vector<16x4xf32> -> vector<4xf32>
```
This should have the exact same semantics as vector.extract, just doing multiple extracts at once.
I would much rather have this form of the operation, it is much closer to vector.extract and works for N-D vectors much better.
https://github.com/llvm/llvm-project/pull/141457
More information about the Mlir-commits
mailing list