| Issue |
239651
|
| Summary |
[MLIR][SCF] `affine-loop-coalescing` creates an invalid delinearization basis for a zero-trip loop nest
|
| Labels |
mlir
|
| Assignees |
|
| Reporter |
pingshiyu
|
Reproduced with the optimized LLVM Git `main` build at commit `fb288ec4774f8664b165f6e302db5be8b30a41da` from 2026-11-04.
The following program is valid:
```mlir
func.func @zero_trip() {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
scf.for %i = %c0 to %c1 step %c1 {
scf.for %j = %c0 to %c0 step %c1 {
scf.yield
}
scf.yield
}
return
}
```
```console
mlir-opt repro.mlir '--pass-pipeline=builtin.module(func.func(affine-loop-coalescing))' -o /dev/null
```
The program verifies, but the pass fails after creating an invalid operation:
```text
error: 'affine.delinearize_index' op no basis element may be statically non-positive
note: see current operation: %...:2 = "affine.delinearize_index"(...) <{static_basis = array<i64: 1, 0>}> : (index) -> (index, index)
```
The inner loop has a legal positive step but zero iterations. Intuitively, the pass should either decline to coalesce this nest, or replace the zero-trip nest while preserving result semantics.
## Related cases
Closed #181590 concerns a zero-step/dynamic-bound cast failure. The current implementation explicitly rejects known-zero steps; this reproducer has step one and instead exposes a zero trip count in the delinearization basis. Open #216289 concerns captured outer loop-carried values and a semantic miscompile on nonempty loops; this reproducer has no loop-carried values and fails verification. Neither report covers this mechanism.
## LLM-Suggested Cause
`coalesceLoops` rejects a known-zero step but not a known-zero normalized trip count. It passes all normalized upper bounds to `delinearizeInductionVariable`, which creates `affine.delinearize_index` for index induction variables. That operation requires every static basis element to be positive.
## LLM Declaration
LLM was used to prepare the bug report, and the bug itself was found and verified by a human.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs