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

Han-Chung Wang llvmlistbot at llvm.org
Fri May 31 10:18:01 PDT 2024


================
@@ -1607,7 +1607,23 @@ struct ChainedReduction final : OpRewritePattern<vector::ReductionOp> {
   }
 };
 
-/// For vectors with either leading or trailing unit dim, replaces:
+VectorType dropNonScalableUnitDimType(VectorType inVecTy) {
+  auto newVecBuilder = VectorType::Builder(inVecTy);
+  auto inVecShape = inVecTy.getShape();
+  SmallVector<int64_t> newShape;
+  SmallVector<bool> newScalableDims;
+  for (auto [dim, isScalable] :
+       llvm::zip(inVecShape, inVecTy.getScalableDims())) {
+    if (dim != 1 || isScalable) {
+      newShape.push_back(dim);
+      newScalableDims.push_back(isScalable);
+    }
----------------
hanhanW wrote:

style nit: prefer using early-exit and continue to simplify code. It also saves the levels of nesting for us.

```suggestion
    if (dim == 1 && !isScalable)
      continue;
    newShape.push_back(dim);
    newScalableDims.push_back(isScalable);
```

https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code

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


More information about the Mlir-commits mailing list