Repository navigation
feat(unroll): recognize an exit test that adds a constant to the counter - #1321
Conversation
`while i + c <op> n` (a tile walk: stop while a whole tile still fits) was not unrolled, and the warning said the loop had no induction variable. The guard match only accepted the counter itself on one side of the compare. analyze_guard now also matches `i + c` / `c + i` / `i - c` on exactly one side and records iv_offset; a constant bound is normalized to n - c with checked arithmetic. Full unroll skips when i + c can wrap at the first or last test; partial unroll adds one no-wrap compare to its group guard. The WGMMA counted-loop matchers keep refusing an offset test. A loop with a counter but an unrecognized exit test gets its own warning. Tests: induction and unroll host tests for both sides, negative offsets, overflowing limits, high-bit unsigned constants, both-sides-variable, and the two wrap cases; an unroll_smoke kernel with exact expected values. Signed-off-by: midagedev <[email protected]>
Signed-off-by: nihalpasham <[email protected]>
nihalpasham
left a comment
There was a problem hiding this comment.
The offset handling looks sound: full unrolling checks the counter and tested expression through the exit test, while partial unrolling sends wrapping groups back to the original loop.
I added behavior checks for the generated guard across signed/unsigned boundaries, plus full-unroll result checks for descending and high-bit cases. At 12d61bca, the three affected host suites passed (585 tests) and strict Clippy was clean. unroll_smoke and unroll_bounds_check passed on B200; smoke memcheck and synccheck each reported 0 errors.
GPU verification used the LLVM path. The libNVVM paths and full repository/hosted checks have not been rerun here.
There was a problem hiding this comment.
The offset handling looks sound: full unrolling checks the counter and tested expression through the exit test, while partial unrolling sends wrapping groups back to the original loop.
I added behavior checks for the generated guard across signed/unsigned boundaries, plus full-unroll result checks for descending and high-bit cases. At 12d61bca, the three affected host suites passed (585 tests) and strict Clippy was clean. unroll_smoke and unroll_bounds_check passed on B200; smoke memcheck and synccheck each reported 0 errors.
GPU verification used the LLVM path. The libNVVM paths have not been rerun here.
At 12d61bca, hosted tests, lint/format checks, guards, docs/book and example compilation passed.
#[unroll]now recognizes a counted loop whose exit test adds or subtracts a constant from the counter, including tile walks:Previously this was reported as having no recognized counter. The analysis now records the offset and normalizes constant limits. Full unrolling refuses counter/test wraparound; partial unrolling guards complete groups and retains the source loop for the remainder. WGMMA counted-loop matching still rejects offset guards.
Coverage includes guard recognition, exact full-unroll results, fixed-width guard behavior across signed/unsigned boundaries, and GPU tile-walk/full/partial examples.
Verified at
12d61bca: 585 host tests across mir-transforms, mir-lower, and dialect-mir; strict Clippy; B200/sm_100 LLVM runs ofunroll_smokeandunroll_bounds_check; smoke memcheck/synccheck each with 0 errors. The libNVVM GPU paths were not rerun. No speedup has been measured.At
12d61bca, hosted tests, lint/format checks, guards, docs/book and example compilation passed. CodeQL was still running at the final review check.