[Mlir-commits] [mlir] [mlir][linalg] Improve linalg.pack consumer fusion. (PR #148993)

Ege Beysel llvmlistbot at llvm.org
Thu Jul 17 04:19:29 PDT 2025


================
@@ -916,12 +903,25 @@ struct PackOpTiling
         // (0,0)~(0,4) at first row.
         // 2. the second slice is extracted from (5) to (9) and SHOULD BE
         // respectively inserted into two rows with different length, including
-        // first row: (0,5) and second row (1,0)~(1,3). It is hard to coordinate
-        // them, thus adding below constraint to bypass them temporarily. In
-        // another word, we can only support tiling with consumer if the tile
-        // size for the producer is a multiple of the inner tile size for the
-        // packed dimensions at this moment.
-        if (failed(cstSize) || !cstInnerSize || *cstSize % *cstInnerSize != 0) {
+        // first row: (0,5) and second row (1,0)~(1,3).
+        // It is hard to coordinate them, thus adding below constraint to bypass
+        // them temporarily. In another word, we can only support tiling with
+        // consumer if the tile size for the producer is either a multiple of
+        // the inner tile size for the packed dimensions or the dimension is not
+        // tiled at this moment.
+        FailureOr<int64_t> cstTileSize =
+            ValueBoundsConstraintSet::computeConstantBound(
+                presburger::BoundType::UB, sizes[dim],
+                /*stopCondition=*/nullptr, /*closedUB=*/true);
+        std::optional<int64_t> cstInnerSize =
+            getConstantIntValue(dimAndTileMapping[dim]);
+        int64_t dimSize = packOp.getSourceType().getDimSize(dim);
+        // TODO: It could be untiled if the `dimSize` is dynamic. It is a hard
+        // check to determine if a dimension is tiled or not.
+        bool isTiled = failed(cstTileSize) || ShapedType::isDynamic(dimSize) ||
+                       cstTileSize.value() != dimSize;
+        if (isTiled && (failed(cstTileSize) || !cstInnerSize ||
----------------
egebeysel wrote:

nit: maybe a comment here explaining what you've written in the PR description could be nice.

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


More information about the Mlir-commits mailing list