Skip to content

[AUTOMATED] Print a rotated counted loop's != latch as the ordering test its guard checks (looptest) - #1906

Merged
mahaloz merged 7 commits into
mainfrom
feat/looptest2
Nov 23, 2026
Merged

mahaloz merged 7 commits into
mainfrom
feat/looptest2

Conversation

@mahaloz

@mahaloz mahaloz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

A rotated for (i = 0; i < n; i++) tests i != n at the bottom behind an if (n > 0) guard. Those are not the same test (a negative n passes i != n), so looptest kept such loops as guarded do-whiles:

printf '4885f67e1031c0488904c74883c0014839f075f3c3c3' | xxd -r -p > count.bin
kuna decompile count.bin 0x100000 --raw-image --target x86:LE:64:default:gcc --base 0x100000

Before:

  if (1 <= a1) {
    v1 = 0;
    do {
      *(long *)(a0 + v1 * 8) = v1;
      v1 += 1;
    } while (v1 != a1);
    return;
  }

After:

  v1 = 0;
  while (v1 < a1) {
    *(long *)(a0 + v1 * 8) = v1;
    v1 += 1;
  }
  • When the latch compares a carried value x that steps by a constant s with an invariant bound b, x starts strictly on the near side of b, and b - x_entry is an exact multiple of s, then x meets b and never passes it. So x != b and x < b (x > b when counting down) agree on every value the top test sees, and no step can wrap. The loop then prints the ordering test, and the guard must equal its entry test x_entry < b. This is part of looptest proven; there is no new option or value.
  • The exact-multiple condition holds for a step of 1, for &x[n] with the element size as the step (C pointer arithmetic), and for x + n * c with a power-of-two step dividing c. Bounds such as a + (n - 1) + 1 in 32 bits fail the guard check (at n == 0 they are far past a) and stay do-while loops, as does a step of 2 against an arbitrary n.
  • The signedness is the one C uses for the printed comparison: both operands must be declared (after signedness rounding) as signed integers, as unsigned integers, or as pointers. A constant bound must lie in [0, 2^31).
  • The condition normal form learns that element pointers compare as their indices (p < &p[n] is 0 < n, &p[16] != &p[32] is true) and that a zero- or sign-extended value compares with a constant at its own width.

Tests: new stage test kuna-looptest-order covers a count down to zero, a byte walk to &p[n] with a signed n, and two loops that must stay do-while (an odd step and the (n - 1) + 1 end pointer). kuna-looptest now expects while (i < n) for its count function. Unit tests cover the new normal-form rules and the exact-multiple check. 0/675 datatest assertions move.

On the decbench O2 corpus 74 more functions match the source's control flow exactly (gained 74, lost 0); O0 is unchanged.

Model: anthropic/claude-opus-5-5

🤖 Generated with Claude Code

https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU

mahaloz and others added 7 commits November 23, 2026 11:49
…d checks (looptest proven)

A rotated `for (i = 0; i < n; i++)` tests `i != n` at the bottom behind
`if (n > 0)`; the two are not the same test, so looptest kept the guarded
do-while. When the latch compares a carried value that steps by a constant s
with an invariant bound, the value starts strictly on the near side of the
bound, and the bound is the start plus an exact multiple of s (s == 1, an
element pointer &x[n] with s the element size, or x + n*c with a power-of-two
s dividing c), the value meets the bound and never passes it: `!=` and `<`
(`>` counting down) agree on every value the top test sees and no step wraps.
The latch then prints as the ordering test, provided its entry test equals
the guard (which is dropped) or a dominating condition, and both operands
print with types of one ordering class (signed, unsigned or pointer, from
the declaration after signedness rounding). The condition normal form
learns that element pointers compare as their indices and that an extended
value compares with a constant at its own width. New stage test
kuna-looptest-order; kuna-looptest's count now expects `while (i < n)`.

[AUTOMATED]

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
The stage corpus count moves by one for kuna-looptest-order, the phase
catalog fixture and docs/options.md carry the looptest summary's new
sentence, and the stages baseline gains the eight LOOPTEST-ORDER assertions
and renames LOOPTEST #3, #7 and #8 for count's new top test.

[AUTOMATED]

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
@mahaloz
mahaloz merged commit 60b8400 into main Nov 23, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/looptest2 branch November 23, 2026 13:49
mahaloz added a commit to sjkim1127/kuna that referenced this pull request Nov 23, 2026
Resolve the stage-corpus count (884 on main after Noelo-Lab#1906, +1 here = 885) and
synthesize docs/baseline-stages.json from both sides (main 5187 + 5 = 5192).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
mahaloz added a commit that referenced this pull request Nov 23, 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