Skip to content

Raising: unroll invariant-yield do-whiles - #3013

Closed
wsmoses wants to merge 1 commit into
mainfrom
pb/dowhile-unroll
Closed

wsmoses wants to merge 1 commit into
mainfrom
pb/dowhile-unroll

Conversation

@wsmoses

@wsmoses wsmoses commented Aug 28, 2026

Copy link
Copy Markdown
Member

A rotated strided-copy loop (k = tid; do { copy(k); } while (k < n) with the increment folded by the range analysis) arrives as an scf.while whose after region yields only loop-invariant values or pass-throughs of the condition-forwarded ones: every iteration past the second would repeat the second's state exactly, so a third implies the original program never terminates. Unroll it to body(init); if (cond) body(invariant), selecting the forwarded results accordingly.

This is one of the normalizations behind the bilininteg_curlcurl_pa family raising strict in the MFEM CUDA→xla-gpu campaign (#2968). Stacked on #3006 (base pb/buffer-normalizations) for the preprocessing-round scaffolding.

Includes a lit test of the rotated strided-copy shape raising end to end.

🤖 Generated with Claude Code

https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD

A rotated do-while whose yields are loop-invariant (or in-body values
computed only from invariants) repeats its state after one iteration, so
a terminating loop runs at most twice: unroll to the first body plus a
guarded second, tolerating side ops in the after region (the barrier
between halves of a ping-pong clones ahead of the second body).

The unroll clones and erases whole host regions - a do-while wrapping a
kernel launch duplicates the launch-carrying body - so wrapper handles
are only stable per phase: preprocess by deduplicated root, then
re-collect the wrappers that survive before the per-wrapper passes.

Rebased onto main from the buffer-normalization stack.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
@wsmoses
wsmoses changed the base branch from pb/buffer-normalizations to main August 30, 2026 12:59
@wsmoses
wsmoses force-pushed the pb/dowhile-unroll branch from d752628 to d04ef91 Compare August 30, 2026 12:59
@wsmoses

wsmoses commented Sep 2, 2026

Copy link
Copy Markdown
Member Author

Superseded by #3071, which moves this unroll into canonicalize-parallel (so it runs before the final llvm-to-affine-access and frees allocas carried through the loop, tmop assemble diag) and fixes a soundness hole: this PR accepts any pass-through of a forwarded condition operand as invariant, so its own @dowhile test (%next = %k + 16, scf.condition(%cond) %next, scf.yield %j) is a real strided loop that gets unrolled to two iterations. #3071 requires the forwarded value itself to be invariant and the exit test to be pure over the carried state.

@wsmoses wsmoses closed this Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant