Skip to content

[AUTOMATED] feat(p8): returndup default-ON, superseding the DIV-18 revert (DIV-54) - #246

Merged
mahaloz merged 1 commit into
mainfrom
feat/returndup-default-on
Aug 3, 2026
Merged

mahaloz merged 1 commit into
mainfrom
feat/returndup-default-on

Conversation

@mahaloz

@mahaloz mahaloz commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Flips returndup (angr SAILR gotoless ReturnDuplicatorHigh,
p8_structure/kuna_returndup.rs) from default-OFF to default-ON as DIV-54.

The history — and why the old number does not apply

This option has shipped as a default once before and was pulled back.

DIV-18 made returndup a default.
2026-07-05 reverted (#136) — decbench measured −976 aggregate GED-perfect across 21,768 firings. Opt-in ever since.
#137 made the pass selective: ported angr's ReturnDuplicatorHigh._should_duplicate_dst const-return gate as Funcdata::returndup_is_const_ret (substrate/funcdata_block.rs).
now the −976 no longer describes the code that ships.

The −976 was measured on the unselective pass, which also split
return <variable> epilogues. The const-return gate declines every share whose return
value is not a literal / COPY chain / phi-of-constants and drops ~40–60% of firings —
precisely the over-eager class the −976 was counting. So this PR does not reinstate the
default on the old evidence; the option is re-measured from scratch.

The A/B

Isolating ablation, the same binary in both arms (decompile-all --json --max-fn-seconds 120, once as shipped and once with --option returndup off), 536
slices / 52,862 scored functions, scored with decbench's own GEDMetric:

scope n GED sum ON GED sum OFF GED-perfect ON GED-perfect OFF
O2 22,549 472,422 476,294 7,211 7,018
O2-noinline 30,313 332,267 336,151 10,825 10,601
both 52,862 804,689 812,445 18,036 17,619

+417 GED-perfect and −7,756 aggregate GED. 608 perfects created against 191
destroyed (3.2 : 1); 3,676 functions improved against 2,079 worsened. Harness
controls: the 46,005 functions the pass never fires on score identically in both
arms
, and the published kuna_update-passwd.c reproduces byte for byte.

Nine partitions were tested causally — split count, void vs value return, distinct
return values, return count, contains-a-switch, all-returns-identical, body size,
project, opt level — and every cell is net-positive. The single net-negative
subpopulation is a split that de-structures a loop (321 firings, −257 GED); a gate for
it was built and scored at +2 perfect / −209 GED and was not kept. Full
analysis: docs/decbench/returndup-regression-triage.md (#245).

The ablation — and a correction to #245

make test: 675/675, PARITY OK, docs/baseline.json untouched.

docs/decbench/returndup-regression-triage.md claimed the raw flip gave "675/675 —
zero assertion movement". Re-measured here on current main, that is wrong: the
raw flip moves 16 assertions across 9 upstream datatest files. This PR corrects that
claim in the triage doc.

Every one of the 16 is an upstream test pinning the merged shared-epilogue rendering
that this option exists to split — e.g. condexesub:

/* returndup off — what the datatest pins */    /* returndup on */
void func(void) {                               void func(void) {
  v1 = other();                                   v1 = other();
  glob1->w = '\x01';                              glob1->w = '\x01';
  if (v1) {                                       if (!v1)
    v1->z = '\0';                                   return;
    v1->y = '\0';                                 v1->z = '\0';
    v1->x = '\0';                                 v1->y = '\0';
  }                                               v1->x = '\0';
  return;                                         return;
}                                               }

675/675 is therefore reached the way every prior default flip in this repo reached
it — a per-test option returndup off on the files whose rendering it changes
(DIV-14: "0/675 via per-test opt-outs in 12 files"; likewise DIV-17, DIV-23, DIV-25,
DIV-51) — with no baseline re-pin. make test-stages is 356/356 PARITY OK with
no baseline re-record either.

Speed — inside the +5% budget

Interleaved A/B on one binary (--option returndup off|on, alternating within each
pair and flipping the within-pair order every other pair), decompile-all --mode reliable, medians:

binary off on Δ pairs
base-passwd update-passwd -O0 494.3 ms 502.9 ms +1.74% 7
coreutils factor -O0 2,409.9 ms 2,427.6 ms +0.74% 7
coreutils ls -O0 6,927.9 ms 7,006.9 ms +1.14% 7
gzip -O0 2,389.9 ms 2,453.4 ms +2.66% 9
gzip -O2 4,809.9 ms 4,753.3 ms −1.18% 7
coreutils sort -O2 12,944.2 ms 12,947.3 ms +0.02% 7

Worst case +2.96% (gzip -O0 at 5 pairs; +2.66% at 9). Per-function, interleaved,
medians of 9: ls main 247.8 → 253.9 ms (+2.45%), factor factor 111.9 → 112.1 ms
(+0.17%), update-passwd xmalloc 103.0 → 103.4 ms (+0.34%), gzip main 519.8 → 376.8 ms
(−27.5%).

python -m scripts.pipeline.timeit is not usable on this host. It times all-OFF
then all-ON in blocks, and the box runs concurrent build agents, so the block boundary
picks up load drift: it reported factor::factor at −33.9% and, on a re-run minutes
later, −0.5%; and ls::main at +57.3%, where the interleaved measurement of the
same function gives +2.45%. Its output is recorded in the DIV row for the record,
but the interleaved numbers above are the measurement.

Tests that needed a per-test opt-out

Datatests (10) — each pins an upstream merged-epilogue rendering:
ccmp, orcompare, condexesub, copytrim, condconst2, bitfields2,
partialunion, statuscmp, union_datatype (the 9 whose own assertions move), plus
condconst — whose assertions do not move, but which drives the
verify_w10_merge_cluster w10 byte-parity oracle (condconst_copy must stay
byte-identical to the C++ render).

Stage tests (5) — two-pass isolation tests where returndup is now a second variable
between the passes: gh6904-ppc-e500-concat44, gh9203-condexe-loopcopy,
ghangr-1after909-doit-73591e, ghangr-earlyreturn,
ghangr-ite-region-converter-missing-5db28e.

Already explicit, prose updated only: ghangr-returndup (pass 1 already set the
option off "to guard against a future default-on sweep") and modes-aggressive.

Rust tests: architecture/tests.rs — apply_mode_reliable_is_a_no_op now asserts
the shipped default survives the no-op preset, and the aggressive test drops
returndup from its off-by-default precondition list.

--mode aggressive keeps naming the option

AGGRESSIVE_OVERRIDES deliberately keeps ("returndup", "on") even though it is now a
default: the preset owns the option, so an earlier --option returndup off on the
same command line is re-enabled by the preset, and the preset's contract ("every
recovery pass on") does not silently change if a default drifts back.
tests/stages/modes-aggressive.xml now pins exactly that — pass 1 sets the option off
explicitly, mode reliable (an empty override list) leaves it off, mode aggressive
restores it. The assertion name is unchanged so the stages baseline needs no re-record.

Also folded in

docs/agents.md gains the worktree spec-resolution trap: KUNA_SPECS/SLEIGHHOME do
not reach the cargo workspace suite, which resolves specs as <repo>/specs relative
to its own crate — so ~22 targets fail with "Could not find .sla file" in a worktree
unless the main tree's built .sla files are symlinked in first. This has now cost two
agents time.

Gates

gate result
make test PARITY OK (675/675) — docs/baseline.json unchanged
make test-stages PARITY OK (356/356) — docs/baseline-stages.json unchanged
make rust-test green
make check-spec green
kuna catalog --check green

Docs

  • docs/history.md — DIV-54 row; the DIV-18 row is annotated SUPERSEDED, not deleted.
  • docs/spec/08-structuring.md — the returndup section is rewritten from "shipped,
    then reverted (history)" to the shipped-default description, carrying the full
    shipped → reverted → re-shipped record and the loop-cell result.
  • docs/options.md + tests/fixtures/phase_catalog.json regenerated; phases.toml
    use_when/summary rewritten for the flip (required for a transform-tier default).
  • docs/modes.md — the aggressive caveat and the option list.
  • docs/decbench/returndup-regression-triage.md — conclusions 2 and 3 corrected.

🤖 Generated with Claude Code

https://claude.ai/code/session_011RXVU58TKJxb518oViChwo

…vert (DIV-54)

`returndup` (angr SAILR gotoless ReturnDuplicatorHigh, p8_structure/kuna_returndup.rs)
becomes a shipped default again.

WHY THE OLD NUMBER IS STALE. DIV-18 first made it a default and it was reverted on
2026-07-05 after decbench measured -976 aggregate GED-perfect across 21,768 firings.
That measurement described the UNSELECTIVE pass, which also split `return <variable>`
epilogues. #137 then ported angr's `_should_duplicate_dst` const-return gate
(`Funcdata::returndup_is_const_ret`), which declines every share whose return value is
not a literal / COPY chain / phi-of-constants and drops ~40-60% of firings -- exactly
the over-eager class the -976 was counting. The revert's justification no longer
describes the code, so the option is re-measured from scratch here rather than
reinstated on the old evidence.

THE NEW MEASUREMENT. Isolating decbench A/B, same binary in both arms, 536 slices /
52,862 scored functions: ON 804,689 aggregate GED / 18,036 GED-perfect versus OFF
812,445 / 17,619 -- +417 perfect and -7,756 GED, 608 perfects created against 191
destroyed (3.2:1). The 46,005 functions the pass never fires on score identically in
both arms. Net-positive in all nine partitions tested causally; the one net-negative
cell (a split that de-structures a loop) had a gate built and scored at +2 perfect /
-209 GED and was not kept. Analysis: docs/decbench/returndup-regression-triage.md.

ABLATION. The raw flip moves 16 datatest assertions across 9 upstream files. Those
files take a per-test `option returndup off` (the standing convention, as DIV-14/17/
23/25/51 did) and the gate is then 675/675 PARITY OK with NO baseline re-pin. A 10th
datatest (condconst.xml) takes the opt-out for the w10 byte-parity oracle that drives
it. Stages: 356/356 PARITY OK with the same opt-out on 5 two-pass isolation tests, and
no baseline re-record.

SPEED. Interleaved A/B on one binary, `decompile-all --mode reliable`, medians:
update-passwd +1.74%, coreutils factor +0.74%, coreutils ls +1.14%, gzip -O0 +2.66%,
gzip -O2 -1.18%, coreutils sort -O2 +0.02% -- worst case +2.96%, inside the +5%
budget. (The blocked `scripts.pipeline.timeit` form is unusable on this host: it
reported ls::main at +57.3% where the interleaved measurement gives +2.45%.)

`--mode aggressive` deliberately keeps naming the option so the preset re-enables it
after an explicit `--option returndup off`; modes-aggressive.xml pins that.

Also records the worktree spec-resolution trap in docs/agents.md: KUNA_SPECS/
SLEIGHHOME do not reach the cargo workspace suite, which resolves specs as
<repo>/specs.

Gates: make test PARITY OK 675/675; make test-stages PARITY OK 356/356;
make rust-test green; make check-spec OK; kuna catalog --check OK.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011RXVU58TKJxb518oViChwo
@mahaloz
mahaloz merged commit 9623dc2 into main Aug 3, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/returndup-default-on branch August 3, 2026 04:35
mahaloz added a commit that referenced this pull request Aug 11, 2026
…ections it forced

Round 4 targeted the slice the campaign had not attacked: the O0 cases where IDA's GED
is 0 and kuna's is not. This lands the reusable parts only -- the instrument, the
analysis, and the two documentation errors the round proved. The per-case triage records
are deliberately not committed.

## The instrument

`scripts/decbench/optsweep.py` -- a bidirectional corpus-scale A/B for any single option
flip. `rescore` prices ONE mined case, which is the wrong unit for anything that changes
a default: the mining pipeline only ever produces one direction of evidence, mining
losses and never pricing the wins the same change destroys. At O0 the net deficit against
IDA is 129 functions while every candidate cluster is 300-430 wide, so a change that
flips 400 each way moves the scoreboard by zero and nothing upstream of this tool would
show it.

It reports both directions of movement by name, the summed GED delta per population, a
per-project and per-architecture breakdown, and the standing-requirement-8 changed set,
with three harness controls built in: functions the pass never fires on must score
identically in both arms, banner-only diffs must score identically, and the ON arm must
reproduce the published column. A run that fails any of them is not a measurement.

Cross-validated against the ad-hoc harness that produced the returndup measurement:
157 of 157 functions agree in both arms on O0 zlib.

## Correction 1: the scored column is `aggressive`, not `reliable`

`docs/decbench-loop.md` has been telling every triage agent that the benchmark injected
`option listing on`, the equivalent of `--mode reliable`. It does not.
`decbench/decompilers/raw/kuna_raw.py`'s `_build_command` builds `kuna decompile-all
<bin> --json --max-fn-seconds 120`, appends `--mode` only when `DECBENCH_KUNA_MODE` is
set, and appends `--option` only from `config.extra_options`, which is empty. So the
benchmark ran `--mode auto` = aggressive on 768 of 803 binaries. An aggressive-only
regression is therefore INSIDE the published number, and any triage that assumes
`reliable` mis-attributes it.

## Correction 2: DIV-54's evidence never saw O0

`docs/decbench/returndup-o0-measurement.md` is the A/B that PR #246 did not run. #246
flipped `returndup` default-ON on 52,862 functions at O2 and O2-noinline; its table has
two rows and neither is O0. Re-run over all three levels, 85,195 scored functions:
O0 -192 GED-perfect, O2 +362, O2-noinline +470, total +640.

Keep the default -- flipping back buys 192 at O0 and sells 832. But one structural
sub-shape carries essentially all the O0 harm and almost none of the O2 benefit: the
split that permanently blocks `rule_block_or` from folding a short-circuit chain (-665
at O0, +15 and +20 at the optimized levels). That is the gate PR #285 implements.

## The grounding

`docs/decbench/round4-grounding.md` locates the gap before triaging anything. O0 is the
only optimisation level where IDA holds more perfect functions than kuna; at O2 and
O2-noinline kuna's lower percentage is a denominator effect, since it is scored on 2,343
more functions and holds more perfect at both. Total perfect: kuna 33,146, IDA 32,838.

`docs/decbench/features-round4.md` is the ranked menu with its killed list. Zero symptoms
fell to the adversarial pass, and four of six filed root causes were materially
overturned -- continuing the campaign's most reliable finding exactly.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01C8UQbPqALzdUQ3cLLjUeKH
mahaloz added a commit that referenced this pull request Aug 11, 2026
…ections it forced (#279)

Round 4 targeted the slice the campaign had not attacked: the O0 cases where IDA's GED
is 0 and kuna's is not. This lands the reusable parts only -- the instrument, the
analysis, and the two documentation errors the round proved. The per-case triage records
are deliberately not committed.

## The instrument

`scripts/decbench/optsweep.py` -- a bidirectional corpus-scale A/B for any single option
flip. `rescore` prices ONE mined case, which is the wrong unit for anything that changes
a default: the mining pipeline only ever produces one direction of evidence, mining
losses and never pricing the wins the same change destroys. At O0 the net deficit against
IDA is 129 functions while every candidate cluster is 300-430 wide, so a change that
flips 400 each way moves the scoreboard by zero and nothing upstream of this tool would
show it.

It reports both directions of movement by name, the summed GED delta per population, a
per-project and per-architecture breakdown, and the standing-requirement-8 changed set,
with three harness controls built in: functions the pass never fires on must score
identically in both arms, banner-only diffs must score identically, and the ON arm must
reproduce the published column. A run that fails any of them is not a measurement.

Cross-validated against the ad-hoc harness that produced the returndup measurement:
157 of 157 functions agree in both arms on O0 zlib.

## Correction 1: the scored column is `aggressive`, not `reliable`

`docs/decbench-loop.md` has been telling every triage agent that the benchmark injected
`option listing on`, the equivalent of `--mode reliable`. It does not.
`decbench/decompilers/raw/kuna_raw.py`'s `_build_command` builds `kuna decompile-all
<bin> --json --max-fn-seconds 120`, appends `--mode` only when `DECBENCH_KUNA_MODE` is
set, and appends `--option` only from `config.extra_options`, which is empty. So the
benchmark ran `--mode auto` = aggressive on 768 of 803 binaries. An aggressive-only
regression is therefore INSIDE the published number, and any triage that assumes
`reliable` mis-attributes it.

## Correction 2: DIV-54's evidence never saw O0

`docs/decbench/returndup-o0-measurement.md` is the A/B that PR #246 did not run. #246
flipped `returndup` default-ON on 52,862 functions at O2 and O2-noinline; its table has
two rows and neither is O0. Re-run over all three levels, 85,195 scored functions:
O0 -192 GED-perfect, O2 +362, O2-noinline +470, total +640.

Keep the default -- flipping back buys 192 at O0 and sells 832. But one structural
sub-shape carries essentially all the O0 harm and almost none of the O2 benefit: the
split that permanently blocks `rule_block_or` from folding a short-circuit chain (-665
at O0, +15 and +20 at the optimized levels). That is the gate PR #285 implements.

## The grounding

`docs/decbench/round4-grounding.md` locates the gap before triaging anything. O0 is the
only optimisation level where IDA holds more perfect functions than kuna; at O2 and
O2-noinline kuna's lower percentage is a denominator effect, since it is scored on 2,343
more functions and holds more perfect at both. Total perfect: kuna 33,146, IDA 32,838.

`docs/decbench/features-round4.md` is the ranked menu with its killed list. Zero symptoms
fell to the adversarial pass, and four of six filed root causes were materially
overturned -- continuing the campaign's most reliable finding exactly.


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

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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