Registry Mirror
Skip to content

Conversation

@avrabe

@avrabe avrabe commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

VCR-PERF-002 / #494 — proof-carrying i32.rem_u identity elision

A literal nonzero i32.const divisor makes i32.rem_u unconditionally
total
(WASM rem_u traps only on divisor==0 and has no INT_MIN/-1 overflow —
that's div_s). Under a proven-narrow dividend the modulo is the identity,
so — unlike the general variable-divisor path that only elides the trap guard
and keeps the op — the whole effect-free op is DELETED and the dividend
flows through, exactly like the redundant-mask class. This is the ONE total
subset of synth's "div/rem is never deleted" rule.

Measured beat-LLVM (named public-cover fixture gust_scale, x rem_u 1000, Thumb-2 / cortex-m4)

build gust_scale .text shape
synth, fact-spec ON 2 B bx lr (the identity)
synth, fact-spec OFF (baseline) 24 B general reciprocal-mul-sub
clang -Os (unsigned x % 1000u, thumbv7em-none-eabi -mcpu=cortex-m4) 24 B movw+movt+umull+lsrs+mov.w+mls+bx

synth beats clang -Os by 22 B (12x). The win is REAL and licensed by a
DISCHARGED FACT, not a heuristic drop: LLVM has no range on the dividend (a
dissolved WASM primitive), so -Os must emit the full reciprocal sequence;
synth's WASM-level ValueRange fact makes the entire sequence dead.

The certifying fact (proof-carrying, non-vacuous)

The elision fires only when ordeal QF_BV returns UNSAT on:

P ∧ (dividend bvurem 1000) ≠ dividend

where dividend bvurem 1000 is the real bvurem term emitted by
WasmSemantics::encode_op(I32RemU, ..) (wasm_semantics.rs:81), and P is the
ingested wsc.facts ValueRange premise x ∈ [0, 999]. Every Unsat carries an
LRAT proof validated by ordeal-lrat. If the fact is absent, or too wide (x can
reach 1000), the check is Sat and synth declines loudly — the general
lowering stands. A variable divisor also declines (its zero-guard is a
control-flow effect; only a syntactic i32.const C, C≠0 qualifies).

Verification (all green)

  • Correctness differential (scripts/repro/fact_spec_rem_494_differential.py):
    in-bounds sweep of 13 values under unicorn — specialized ≡ wasmtime ≡
    unspecialized. Non-vacuity gate: fails unless the certificate-backed identity
    actually fired AND shrank .text.
  • Wrong-bound red path (--fact-hi 4000 --expect-decline): identity declines
    loudly; the surviving op is swept over 6 out-of-bound values (x ≥ divisor,
    the region the identity would have miscompiled) and proven to compute the true
    modulo. (This replaces the salvaged harness's incorrect "byte-identical to
    baseline" assertion — the pre-existing nonzero-divisor zero-guard elision
    legitimately shrinks the declined build 24→18 B; the safety property is
    correctness-by-execution, not a byte proxy.)
  • Flag-off byte-identical: SYNTH_FACT_SPEC=0 ≡ plain compile, identical
    .text sha256 (549feb34…). The lever is flag-gated, default OFF.
  • Frozen anchors intact: frozen_codegen_bytes 10/10 (default-off ⇒ no
    fixture bytes move).
  • 5 unit tests: identity admit, wrong-bound Sat decline, variable-divisor
    decline (op kept + zero-guard still discharged), no-fact decline, pow2 admit.
  • claims.yaml: 18/18 hold (no proof/rule counts changed — this is a flag-off
    specialization lever).

Refs #494. Do NOT merge — review gate.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YJK5LZZEkV5smCY1jKn18L

avrabe and others added 3 commits July 15, 2026 22:17
…subset

VCR-PERF-002 beyond-parity: a literal nonzero i32.const divisor makes
i32.rem_u unconditionally total (traps only on divisor==0; no INT_MIN/-1
overflow — that's div_s). Under a proven-narrow dividend (UNSAT(P ∧
(x bvurem C) ≠ x)) the modulo is the identity, so — unlike the general
variable-divisor path that only elides the trap GUARD and keeps the op —
the whole effect-free op is DELETED and the dividend flows through,
exactly like the redundant-mask class.

The VC is non-vacuous: WasmSemantics::encode_op(I32RemU,..) emits a real
bvurem term, checked UNSAT by ordeal QF_BV with an LRAT certificate.
Flag-off / non-eliding-flag-on take the exact general div/rem path
(guard obligations + havoc), so bytes are unchanged. 5 unit tests:
identity admit, wrong-bound Sat decline, variable-divisor decline (op
kept + zero-guard still discharged), no-fact decline, pow2 admit.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YJK5LZZEkV5smCY1jKn18L
…fication incomplete)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ty region

The salvaged --expect-decline path asserted the declined build was
byte-identical to the OFF baseline. That was wrong-headed: fact-spec ON
always fires the pre-existing nonzero-divisor ZERO-GUARD elision (#494
phase 2b) for a literal nonzero divisor, so the ON build can never equal
the OFF baseline for this fixture (24 -> 18 B). The prior narrative
confused "identity declined" with "no elision fired".

Replace the byte proxy with the actual safety property: under a too-wide
bound the identity declines LOUDLY and the op SURVIVES computing the true
modulo — so sweep OUT-OF-BOUND values (x >= divisor, the exact region the
identity would have miscompiled) and assert specialized == wasmtime ==
unspecialized by execution. Strictly stronger than the byte check.

Both paths green:
  in-bounds  (identity fires):  unspec 24 B -> spec 2 B, 13 values PASS
  wrong-bound (identity declines): spec 18 B, 6 OOB values PASS

clang -Os `unsigned x % 1000u` for thumbv7em/cortex-m4 = 24 B (measured:
movw+movt+umull+lsrs+mov.w+mls+bx, gust_scale st_size 0x18). synth with
the discharged ValueRange fact deletes the whole op to 2 B `bx lr` — a
22 B (12x) beat-LLVM win licensed by UNSAT(P and (x bvurem 1000) != x),
certificate-checked QF_BV, not a heuristic.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YJK5LZZEkV5smCY1jKn18L
@avrabe
avrabe merged commit b69d503 into main Jul 15, 2026
37 checks passed
@avrabe
avrabe deleted the feat/45-494-beat-llvm branch July 15, 2026 20:53
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.40741% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/synth-verify/src/fact_spec.rs 87.40% 17 Missing ⚠️

📢 Thoughts on this report? Let us know!

avrabe added a commit that referenced this pull request Jul 16, 2026
… WasmCert anchor + VCR-ISA 41→50, A64 7→50, 12× beat-LLVM, MC/DC provenance) (#775)

Five oracle-gated lanes across semantics/capability/perf/assurance:
- VCR-WASM-001 (#771): WasmCert-Coq source anchor (i32.add refinement, 474→476)
- VCR-ISA-001 (#773): generate-not-mirror 41→50 ops (476→485 Qed)
- #538 (#769): AArch64 milestone 2 — 7→50 integer ops, honest div/rem decline
- #494 (#770): proof-carrying rem_u elision — 12× beat over clang -Os
- #396 (#774): synth-provenance-v1 MC/DC source-to-object map (VCR-DEC-003)

#757 stays OPEN (accepted residual — 7 reconstructions all green, needs reporter
module; #772 lands them as regression guards). i64.trunc_f64 + #761 residuals noted.


Claude-Session: https://claude.ai/code/session_01YJK5LZZEkV5smCY1jKn18L

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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