[Mlir-commits] [mlir] [mlir][vector] Canonicalize/fold 'order preserving' transposes (PR #135841)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Thu May 1 08:47:19 PDT 2025
================
@@ -5594,6 +5594,29 @@ LogicalResult ShapeCastOp::verify() {
return success();
}
+namespace {
+
+/// Return true if `transpose` does not permute a pair of non-unit dims.
+/// By `order preserving` we mean that the flattened versions of the input and
+/// output vectors are (numerically) identical. In other words `transpose` is
+/// effectively a shape cast.
+bool isOrderPreserving(TransposeOp transpose) {
+ ArrayRef<int64_t> permutation = transpose.getPermutation();
+ ArrayRef<int64_t> inShape = transpose.getSourceVectorType().getShape();
+ int64_t current = 0;
+ for (auto p : permutation) {
+ if (inShape[p] != 1) {
----------------
banach-space wrote:
This logic should also check the scalable flags - otherwise `[1]` will be treated as `1`. Basically, we should disable it for things like this:
```mlir
%1 = vector.transpose %0, [0, 2, 1]
: vector<6x1x[1]xi8> to vector<6x[1]x1xi8>
```
We are very unlikely to ever generate this, but it's better to be safe than sorry.
https://github.com/llvm/llvm-project/pull/135841
More information about the Mlir-commits
mailing list