[Mlir-commits] [mlir] [mlir][linalg] Bail out tensor.cast pack/unpack fold on unprovable tile sizes (PR #188000)

Mehdi Amini llvmlistbot at llvm.org
Wed Mar 25 09:04:15 PDT 2026


================
@@ -5000,8 +5000,10 @@ template SmallVector<int64_t>
 //  * a dim from newPackedTy is static, and
 //  * the corresponding size from mixedTiles is still dynamic.
 // Otherwise, the original tile size is preserved.
+// Returns failure when a dynamic tile cannot be proven to match the static
+// packed dim.
----------------
joker-eph wrote:

This is a very conservative solution, but why wouldn't we just exploit the information and unconditionally drop the dynamic tile size to match the static information we have? I looked at your example in the test and that means that:

```
    %0 = arith.constant 256 : index
    %1 = tensor.empty() : tensor<7x3xi32>
    %cast = tensor.cast %arg0 : tensor<1x3x8x1xi32> to tensor<?x3x?x1xi32>
    %unpack = linalg.unpack %cast inner_dims_pos = [0, 1] inner_tiles = [%0, 1] into %1 : tensor<?x3x?x1xi32> -> tensor<7x3xi32>
```

Would turn into:

```
    %0 = tensor.empty() : tensor<7x3xi32>
    %unpack = linalg.unpack %arg0 inner_dims_pos = [0, 1] inner_tiles = [8, 1] into %0 : tensor<1x3x8x1xi32> -> tensor<7x3xi32>
```

The information is provided by folding the cast away and inferring the tile size from the shape. 

We could also detect the mismatch when possible (like here) and fold to poison...

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


More information about the Mlir-commits mailing list