[Mlir-commits] [mlir] [mlir][linalg] Restrict linalg.pack to not have artificial padding. (PR #149624)
Ege Beysel
llvmlistbot at llvm.org
Tue Jul 22 08:31:09 PDT 2025
================
@@ -220,6 +243,29 @@ struct FoldPadWithPackOp : public OpRewritePattern<PackOp> {
if (!isEqualConstantIntOrValue(paddingValue, constantPaddingValue))
return failure();
+ // Folding is not allowed if it introduces artificial padding.
+ RankedTensorType unpackedType = packOp.getSourceType();
+ SmallVector<int64_t> outerShapeWithoutTranspose =
+ getPackedOuterShapeWithoutTransposition(packOp);
+ for (auto [pos, tileSize, high] :
+ llvm::zip_equal(packOp.getInnerDimsPos(), packOp.getStaticInnerTiles(),
+ padOp.getMixedHighPad())) {
+ if (unpackedType.isDynamicDim(pos))
+ return failure();
+ if (ShapedType::isDynamic(outerShapeWithoutTranspose[pos]))
+ return failure();
+ if (ShapedType::isDynamic(tileSize))
----------------
egebeysel wrote:
Oh, I stand corrected. Thanks!
I was confused by the `verifyCompatibleShape`. One thing I noticed, when we have dynamic inner tile sizes, any result shape is essentially legal, right? including
```mlir
%pack = linalg.pack ... inner_tiles = [%tile] : tensor<7xf32> into tensor<8x?xf32>
```
I know this is also pretty artificial as well, but I don't think `verifyCompatibleShape` checks anything on that regard?
https://github.com/llvm/llvm-project/pull/149624
More information about the Mlir-commits
mailing list