[Mlir-commits] [mlir] [mlir] Add direct vectorization lowering for `tensor.pack` ops (PR #78660)

Han-Chung Wang llvmlistbot at llvm.org
Tue Feb 6 21:20:56 PST 2024


================
@@ -1585,6 +1727,32 @@ vectorizeLinalgOpPrecondition(LinalgOp linalgOp,
   return success();
 }
 
+/// TODO: Use a matcher to check for a constant padding value.
+static LogicalResult
+vectorizePackOpPrecondition(tensor::PackOp packOp,
+                            ArrayRef<int64_t> inputVectorSizes) {
+  auto padValue = packOp.getPaddingValue();
+  if (padValue && !padValue.getDefiningOp<arith::ConstantOp>()) {
+    LDBG("pad value is not constant: " << packOp << "\n");
+    return failure();
+  }
+
----------------
hanhanW wrote:

Hey Max, I just found this might address the concern.

```cpp
// Return the constant attribute, or null if the Operation isn't a constant.
Attribute getConstantAttr(Operation *constantOp) {
  Attribute constant;
  matchPattern(value.getDefiningOp(), m_Constant());
  return constant;
}
```

https://mlir.llvm.org/getting_started/Faq/#many-dialects-define-a-constant-operation-how-do-i-get-a-constant-value-generically

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


More information about the Mlir-commits mailing list