[Mlir-commits] [mlir] [MLIR][Vector]Generalize DropUnitDimFromElementwiseOps (PR #92934)

Benjamin Maxwell llvmlistbot at llvm.org
Wed May 22 02:04:44 PDT 2024


================
@@ -1607,7 +1607,24 @@ struct ChainedReduction final : OpRewritePattern<vector::ReductionOp> {
   }
 };
 
-/// For vectors with either leading or trailing unit dim, replaces:
+FailureOr<VectorType> dropNonScalableUnitDimType(VectorType VT) {
+  VectorType newVT = VT;
+  int removed = 0;
+  auto shape = VT.getShape();
+  auto builder = VectorType::Builder(newVT);
+  for (unsigned i = 0; i < shape.size(); i++) {
+    if (shape[i] == 1 && !VT.getScalableDims()[i]) {
+      newVT = builder.dropDim(i - removed);
+      removed++;
+    }
+  }
+
+  if (removed == 0)
+    return failure();
+  return newVT;
----------------
MacDue wrote:

This has the same issue :sweat_smile:, it's creating a new vector type every time a dimension is dropped. What I meant was: 
```suggestion
  int removed = 0;
  auto shape = VT.getShape();
  VectorType::Builder builder(VT);
  for (unsigned i = 0; i < shape.size(); i++) {
    if (shape[i] == 1 && !VT.getScalableDims()[i]) {
      builder.dropDim(i - removed);
      removed++;
    }
  }

  if (removed == 0)
    return failure();
  return builder;
```

https://github.com/llvm/llvm-project/pull/92934


More information about the Mlir-commits mailing list