You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[mlir][linalg] Fix Linalg runtime verification pass to handle tensors with dimensions of size 0 (llvm#163791)
Runtime verification on Linalg structured ops unconditionally computed
`end - 1` to determine the last iteration index before composing
indexing maps. This caused spurious "negative index" assertion failures
while operating on empty tensors (tensors with a dimension of size 0).
The issue occurs because:
1. Empty tensors create loop ranges [0, 0) with zero trip count
2. Computing end - 1 = 0 - 1 = -1 creates a fictitious negative index
3. The negative index check triggers even though no loop iterations
occur
The fix is to guard all runtime verification with a check that ensures
all loop ranges are non-empty (start < end) before performing any index
arithmetic.
Example MLIR that previously failed:
```mlir
func.func @fill_empty() -> tensor<0xi32> {
%c0 = arith.constant 0 : i32
%empty = tensor.empty() : tensor<0xi32>
%filled = linalg.fill ins(%c0 : i32) outs(%empty : tensor<0xi32>) -> tensor<0xi32>
return %filled : tensor<0xi32>
}
```
---------
Co-authored-by: Hanumanth Hanumantharayappa <[email protected]>
0 commit comments