Repository navigation
[AUTOMATED] Print a rotated loop with its test at the top when that is provably the same program (option looptest) - #1899
Merged
Merged
Conversation
…he same program (option looptest) gcc's loop header copying turns `while (c) body` into `if (c) do body while (c);` and drops the `if` when it proves `c` on entry, so kuna printed do-while loops the source tests at the top. New option looptest (P8, values binary|proven|assume, default proven, C output only) plans each BlockDoWhile on the final structured tree at the top of body emission. The test moves to the top when every loop-variant leaf of the printed condition is a value a header MULTIEQUAL carries into the next iteration (a COPY source prints as the carried variable) and the condition calls nothing, and the entry test (each carried value replaced by its entry value, compared in a small normal form) folds to true, equals a dominating edge's condition, or equals the guard in front of the loop. That guard is left out when the blocks between it and the loop are pure and write nothing the skip path reads, and the skip path reaches the loop's exit or an equal bare return. A guard that must stay, or a carried variable in the stack frame, keeps the do-while. 0/675 datatest assertions move. New stage test kuna-looptest. [AUTOMATED] Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
…age tests to the bottom test The catalog counts, the stage corpus count and the phase-catalog fixture move by one for looptest; docs/options.md is regenerated. Six existing stage tests pin a do-while whose entry test folds to true and now prints top-tested: five add `option looptest binary` (gh9203, endptrbound, repstring x2, stackguard-tailcall, tiedphitrim), and REPFRAMECOPY #9 checks the loop in either spelling. The stages baseline gains the twelve LOOPTEST assertions and loses none. [AUTOMATED] Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
Both probes check what endptrbound does to a loop bound; under looptest the
counted loop and the buffer walk now print `while (c) {` (their entry tests
fold to true), so the bound regexes accept the test at the top or the bottom.
[AUTOMATED]
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An optimizing compiler rotates
while (c) bodyintoif (c) do body while (c);, and kuna prints the rotated form. For this gcc -O2for (p = a; p < a + n; p++) *p = v;:Before:
After:
looptest(P8,binary|proven|assume, defaultproven, C output only). It plans eachdo … whileon the final structured tree and prints it aswhile (c) { body }only when that is the same program; the p-code is not changed.do { q = *p; p = q; } while (q)becomeswhile (p)) and the condition calls nothing.0 < nandn != 0for unsignedn,p == &p[n]andn == 0, constant folding, LOADs only when nothing writes memory in between). Implication is not accepted: with a signedn, a guardn > 0in front ofp != &a[n]keeps the do-while.binaryrestores the old output;assumealso moves the test of loops with no entry proof (speculative, off by default).Tests: new stage test
kuna-looptest(six rotated loops; three lose their guard, one has a constant entry test, two must stay do-while;option looptest binaryrestores all of them) and unit tests for the condition normal form. 0/675 datatest assertions move; six stage tests that pin a do-while with a constant entry test now setoption looptest binary(one checks the loop in either spelling).On the decbench O2 corpus 756 more functions match the source's control flow exactly (gained 760, lost 4, all four real
do … whileloops whose first test is constant); at O0, +9 (gained 9, lost 0).Model:
anthropic/claude-opus-5-5🤖 Generated with Claude Code
https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU