[LinalgExt] Fix WinogradInputTransformOp::verify incorrect dim-1 dynamic check (#24679)
### Problem
`WinogradInputTransformOp::verify` never validates the size of input
dimension 1 for rank-2 inputs.
### Root cause
```cpp
if ((!inputType.isDynamicDim(0) &&
inputType.getDimSize(0) > getInputTileSize()) ||
(inputType.isDynamicDim(1) && // <-- missing `!`
inputType.getDimSize(1) > getInputTileSize())) {
return op->emitOpError("expected input dims not greater than input tile "
"size if input is of rank 2");
}
```
The dim-0 clause guards with `!isDynamicDim(0)`, but the dim-1 clause is
missing the `!`, which makes it dead:
- if dim 1 is **static**, `isDynamicDim(1)` is false, so the clause
short-circuits and the static size is never compared;
- if dim 1 is **dynamic**, `getDimSize(1)` is `ShapedType::kDynamic`
(`INT64_MIN`), and `INT64_MIN > getInputTileSize()` (a small positive
tile size) is always false.
So a rank-2 input whose static dim 1 exceeds the input tile size is
silently accepted, contradicting the op's own diagnostic (`expected
input dims not greater than input tile size if input is of rank 2`).
`verifyCompatibleShape` a few lines below only constrains the output
shape, so nothing else catches it.
### Fix
Add the missing `!`, mirroring the dim-0 clause one line above.
### Testing
Static reasoning only (no local build). I'm happy to add a
`--verify-diagnostics` case to `Dialect/LinalgExt/IR/test/invalid.mlir`,
but there is currently no rank-2 `winograd.input_transform` example
in-tree to mirror, so I left the test out of this minimal one-character
fix — glad to add one if you'd like.
---------
Signed-off-by: Eylon Krause <eylon1909@gmail.com>diff --git a/compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.cpp b/compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.cpp
index 6bb7fe0..0016d82 100644
--- a/compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.cpp
+++ b/compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.cpp
@@ -1695,7 +1695,7 @@
}
if ((!inputType.isDynamicDim(0) &&
inputType.getDimSize(0) > getInputTileSize()) ||
- (inputType.isDynamicDim(1) &&
+ (!inputType.isDynamicDim(1) &&
inputType.getDimSize(1) > getInputTileSize())) {
return op->emitOpError("expected input dims not greater than input tile "
"size if input is of rank 2");
diff --git a/compiler/src/iree/compiler/Dialect/LinalgExt/IR/test/invalid.mlir b/compiler/src/iree/compiler/Dialect/LinalgExt/IR/test/invalid.mlir
index 38db708..466077b 100644
--- a/compiler/src/iree/compiler/Dialect/LinalgExt/IR/test/invalid.mlir
+++ b/compiler/src/iree/compiler/Dialect/LinalgExt/IR/test/invalid.mlir
@@ -1713,6 +1713,18 @@
// -----
+func.func @illegal_winograd_input_rank2_dims(%arg0: tensor<8x100xf32>) -> tensor<8x8xf32> {
+ %0 = tensor.empty() : tensor<8x8xf32>
+ // input tile size = output_tile_size(6) + kernel_size(3) - 1 = 8; dim 1 (100)
+ // exceeds it, which must be rejected for a rank-2 input.
+ // expected-error @+1 {{expected input dims not greater than input tile size if input is of rank 2}}
+ %1 = iree_linalg_ext.winograd.input_transform output_tile_size(6) kernel_size(3) image_dimensions([1, 2])
+ ins(%arg0 : tensor<8x100xf32>) outs(%0 : tensor<8x8xf32>) -> tensor<8x8xf32>
+ return %1 : tensor<8x8xf32>
+}
+
+// -----
+
func.func @illegal_winograd_output_image_dimensions(%arg0: tensor<8x8x1x2x2x32xf32>) -> tensor<1x32x12x12xf32> {
%0 = tensor.empty() : tensor<1x32x12x12xf32>
// expected-error @+1 {{expect image dimensions to be either [1, 2] or [2, 3]}}