[Mlir-commits] [mlir] [MLIR][Vector] Generalize DropUnitDimFromElementwiseOps to non leading / trailing dimensions. (PR #98455)

Hugo Trachino llvmlistbot at llvm.org
Thu Jul 11 03:06:27 PDT 2024


================
@@ -1622,7 +1622,34 @@ struct ChainedReduction final : OpRewritePattern<vector::ReductionOp> {
   }
 };
 
-/// For vectors with either leading or trailing unit dim, replaces:
+// Scalable unit dimensions are not supported. Folding such dimensions would
+// require "shifting" the scalable flag onto some other fixed-width dim (e.g.
+// vector<[1]x4xf32> -> vector<[4]xf32>). This could be implemented in the
+// future.
+static VectorType dropNonScalableUnitDimFromType(VectorType inVecTy) {
+  auto inVecShape = inVecTy.getShape();
+  auto inVecScalableDims = inVecTy.getScalableDims();
+  SmallVector<int64_t> newShape;
+  SmallVector<bool> newScalableDims;
+  if (llvm::all_of(inVecShape, [](int64_t dim) { return dim == 1; }) &&
----------------
nujaa wrote:

I preferred checking early this condition to make it clearer. This multiplies the number of iteration. Another solution is to check whether `newShape` is empty at the end. Please, feel free to give your preference.

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


More information about the Mlir-commits mailing list