[Mlir-commits] [mlir] [mlir][linalg] Fix UBSan division-by-zero in PackOp folding (PR #186271)

Andrzej WarzyƄski llvmlistbot at llvm.org
Wed Mar 25 02:35:16 PDT 2026


================
@@ -1451,6 +1451,24 @@ func.func @fold_pack_constant_splat(%dest : tensor<4x8x8x32xf32>) -> tensor<4x8x
 
 // -----
 
+// Zero tile size: pack must not be folded into expand_shape.
+// CHECK-LABEL: func.func @pack_zero_tile_not_folded
+// CHECK-NOT:     tensor.expand_shape
+// CHECK:         linalg.pack
+func.func @pack_zero_tile_not_folded(%A: tensor<7x16xi32>) -> tensor<1x16x?x1xi32> {
----------------
banach-space wrote:

```suggestion
// Zero tile size: folding would create a pack op with one static tile equal to zero, i.e. invalid IR.
// CHECK-LABEL: func.func @pack_zero_tile_not_folded
// CHECK-NOT:     tensor.expand_shape
// CHECK:         linalg.pack
func.func @no_fold_pack_zero_tile(%A: tensor<7x16xi32>) -> tensor<1x16x?x1xi32> {
```

Also suggesting to update the test function name to use prefixes to mark negative cases: https://mlir.llvm.org/getting_started/TestingGuide/#test-naming-convention

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


More information about the Mlir-commits mailing list