[Mlir-commits] [mlir] [mlir][vector] Determine vector sizes from the result shape in the ca… (PR #88249)

Han-Chung Wang llvmlistbot at llvm.org
Tue Apr 16 09:47:16 PDT 2024


================
@@ -1525,6 +1533,17 @@ vectorizeAsTensorPackOp(RewriterBase &rewriter, tensor::PackOp packOp,
   (void)status; // prevent unused variable warning on non-assert builds.
   assert(succeeded(status) && "failed to reify result shapes");
 
+  ArrayRef<int64_t> resultTensorShape = packOp.getDestType().getShape();
+  bool doMasking = true;
+
+  // If the input vector sizes are not provided, then the vector sizes are
+  // determined by the result tensor shape. In case the vector sizes aren't
+  // provided, we update the inBounds attribute instead of masking.
+  if (inputVectorSizes.empty()) {
+    inputVectorSizes = resultTensorShape.take_front(packOp.getSourceRank());
+    doMasking = false;
+  }
----------------
hanhanW wrote:

nit: if it were me, I'd structure this like:

```
// ....
bool doMasking = true;
if (...) {
  ArrayRef<int64_t> resultTensorShape = ...
  inputVectorSizes ....
  doMasking = false;
}
```

Because

1. The doMasking initialization is related to the comment.
2. The `resultTensorShape` is only used in the if closure.

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


More information about the Mlir-commits mailing list