[Mlir-commits] [mlir] [mlir][linalg] Restrict linalg.pack to not have artificial padding. (PR #149624)

Adam Siemieniuk llvmlistbot at llvm.org
Tue Jul 22 10:38:34 PDT 2025


================
@@ -150,9 +150,10 @@ def Linalg_PackOp : Linalg_RelayoutOp<"pack", [
 
     `padding_value` specifies a padding value at the boundary on non-perfectly
     divisible dimensions. Padding is optional:
-    - If absent, it is UB if the tile does not perfectly divide the dimension.
+    - If absent, it assumes the tile perfectly divides the dimension.
     - If present, it will pad along high dimensions (high-padding) to make the
-      tile complete.
+      tile complete. Note that it is not allowed to have artificial padding that
+      is not strictly required by linalg.pack.
----------------
adam-smnk wrote:

That's a good point and solving it might require careful consideration.

The above example exactly highlights my concern about correctness. If `%src` has any shape other than `<7x1>`, the IR is invalid. In case of shape inference, I'd expect it to propagate to the pack's source first. Only then the packed shape result could be determined.
But as you mentioned, there could be some corner cases where intermediate IR has to rely on UB in between other rewrites.

> I think maybe I can add some doc and say that it is UB if extra padding is requested.

Sounds like a good compromise. Let's mention the UB explicitly here.
Technically, one could have stricter `pack` lowering that could avoid it altogether.

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


More information about the Mlir-commits mailing list