Repository navigation
[PROPOSAL] angr-dd-argmatch-to-argument-noea-9e6e8b: SAILR goto-reduction by return-tail duplication - #57
Merged
Conversation
…(return-tail duplication) angr emits 0 gotos on dd::argmatch_to_argument where kuna emits 1 goto + 1 label to a shared `v2 = 0; return v2;` tail. Closing this needs the proposed S8 goto-reduction pass (kuna_gotoreduce.rs) doing return-tail duplication into the verbatim CollapseStructure engine — large per Hard rule 7 and the recorded decider verdict. This is the simpler return-constant variant of the existing morton `gotoreduce` proposal; file as an additional motivating testcase, not a competing point fix. Analysis + proposal + partial record only; no implementation. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
Author
|
APPROVE |
…ail duplication (option gotoreduce)
New S8 pass `kuna_gotoreduce.rs` (`ActionGotoReduce`, registered after
`ActionFinalStructure`, option `gotoreduce`, default-OFF) implementing angr's
SAILR/Phoenix goto-reduction (ReturnDuplicator) for the return-constant variant.
On `dd::argmatch_to_argument` the only structural diff vs angr was a single
residual `goto label_40a6a3;` + `label_40a6a3:` to a shared `v2 = 0; return v2;`
return tail with two predecessors, which Ghidra's verbatim CollapseStructure must
express as an unstructured edge. The pass finds every `BlockIf` that renders as
`if (cond) goto T` whose target T is a small single-successor basic-block chain
ending in `return` (<=3 blocks / <=8 ops, no call/store) and rewrites it to
`if (cond) { <tail> }` by minting fresh BlockCopy leaves over the same underlying
basic blocks (a print-tree duplication; no p-code cloned, SSA/def-use untouched),
then clears T's now-unused label.
Only genuine graph surgery is one `(kuna)` method
`BlockGraph::kuna_inline_return_tail` in block.rs; the rest is the new module plus
the standard option anchors (architecture/seam flag `reduce_return_gotos`,
options.rs, universalaction.rs, stages.toml). ElementId 4100.
Ablation clean (0/675 datatest assertions change if default-ON) and speed within
budget, but kept default-OFF opt-in: first S8 structured-tree mutation on the
verbatim collapse engine, rated high-risk in the approved proposal. No DIV entry
(default output byte-identical). Stage test
tests/stages/ghangr-dd-argmatch-to-argument-noea-9e6e8b.xml. Snapshot/count test
fixtures (action listing, catalog, settable counts, corpus count) updated for the
new option/action/test.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
mahaloz
marked this pull request as ready for review
June 25, 2026 16:06
…57) Union-resolve the registrations for the gotoreduce opt-in option (angr SAILR ReturnDuplicator goto-reduction) against main, which had advanced with the #55 (loopbreak_recovery/DIV-10) and #67 (macho-arm64e) settables: - architecture.rs / seams.rs / options.rs: union reduce_return_gotos with recover_loop_break/fold_call_returns fields, ctors, resets, set_kuna_option arms, KUNA_OPTION_NAMES, seam-copies - s8_structure/mod.rs: union kuna_gotoreduce + kuna_loopbreak_recovery modules - stages.toml: union the gotoreduce settable; 45 settables now (27 stage-model + 15 analysis + 3 loader caps), surface=91 - gotoreduce ElementId 4100 (no collision: dedup 4091, loopbreak 4092) - catalog provenance counts: angr 10, structure-recovery 6 (gotoreduce both) - count assertions (kuna_stages/tests.rs, catalog_bytecompat.rs, xml.rs corpus 137 files) bumped; regenerate stage_catalog fixture, assertions.md, baseline-stages.json (168/168) - gotoreduce is opt-in (default-off) -> no DIV entry Gates: catalog OK, make test PARITY OK (675/675), make test-stages PARITY OK (168/168). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
mahaloz
added a commit
that referenced
this pull request
Jun 25, 2026
Region-structurer foundation (Inc 0) — analysis-only, no new --option. Main had advanced with #55 (loopbreak_recovery/DIV-10), #57 (gotoreduce), #67 (macho-arm64e); the only conflict was docs/baseline-stages.json (data_footer counts), all other region code (s7_regions/kuna_regiongraph.rs, kuna_regionid.rs, kuna_console.rs) and the kuna-regions.xml assertions merged cleanly. Regenerated assertions.md (45 settables, unchanged) and baseline-stages.json (171/171, incl. the 8 KUNA-REGIONS assertions plus main's gotoreduce/loopbreak/catalog ones). Gates: catalog OK, make test PARITY OK (675/675), make test-stages PARITY OK (171/171). Region unit tests: regionid 6/6, regiongraph 18/18 (incl. new build_from_block_graph_*). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
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.
dd-argmatch-to-argument-noea-9e6e8b: SAILR goto-reduction by return-tail duplication (
option gotoreduce)Closes the one structural gap on angr testcase
test_decompiling_dd_argmatch_to_argument_noeagerreturns::argmatch_to_argument(coreutils
dd, x86-64 @0x40a640). Seedocs/features/dd-argmatch-to-argument-noea-9e6e8b/analysis.mdfor the full side-by-side.
Why angr was better
The only difference was a single residual
goto label_40a6a3;+label_40a6a3:. A sharedreturn tail (
v2 = 0;falling through to the singlereturn v2;) has two predecessors —the entry
if (v2 == 0)true-arm and an in-loopif (v2 == 0)edge — so Ghidra'sCollapseStructure(the verbatim port ofCollapseStructure/TraceDAG/BlockTrace) mustexpress the second edge as an unstructured
goto. It has no schema that duplicates a tail toavoid a goto. angr (SAILR/Phoenix
ReturnDuplicator) emits 0 gotos by duplicating theconstant return tail into the in-loop edge.
Mechanism
New S8 pass
kuna_gotoreduce.rs(ActionGotoReduce), registered afterActionFinalStructure.It finds every
BlockIfthat renders asif (cond) goto Twhose targetTis a smallsingle-successor basic-block chain ending in
return(bounded: ≤3 blocks / ≤8 ops, noCALL/STORE), and rewrites it toif (cond) { <tail> }by minting freshBlockCopyleavesover the same underlying basic blocks (a print-tree duplication — the C printer re-emits
their ops;
CPUI_RETURNcarries thereturnsflag, notbranch, so it survives the if-bodyNO_BRANCH). No p-code is cloned and SSA/def-use is untouched. When the converted goto wasthe only unstructured edge into
T,T's label is cleared. The only genuine graph surgery isone
(kuna)methodBlockGraph::kuna_inline_return_tailinblock.rs; everything else is thenew module plus the standard option anchors.
The option
option gotoreduce on|off(architecture/seam flagreduce_return_gotos, ElementId 4100),default-OFF opt-in — flip per decompilation:
Ablation / parity / speed
off≈148.7ms,on≈105.1ms, Δ≈-29% — theextra post-structuring scan is negligible; the spread is measurement noise).
first S8 structured-tree mutation on the verbatim-ported collapse engine and is rated
high-risk in the approved proposal, so it ships opt-in pending broader validation (no DIV
entry; default output stays byte-identical). A reviewer can flip it default-ON later given
the clean ablation.
kuna catalog --checkOK · datatest parity PARITY OK (675/675) · stage suitePARITY OK (162/162, incl. the new
tests/stages/ghangr-dd-argmatch-to-argument-noea-9e6e8b.xml).This is the same SAILR goto-reduction family as the parked
morton/newburry/tr-buildproposals;
dd::argmatch_to_argumentis the minimalreturn <const>variant of that transform.🤖 Generated with Claude Code
Before / after —
argmatch_to_argumentinddReal captured kuna output on the function this feature was built for, with
option gotoreduceflipped. Ported from angr — test_decompiling_dd_argmatch_to_argument_noeagerreturns; SAILR/Phoenix goto-reduction (return-tail duplication / ReturnDuplicator); argmatch_to_argument.gotoreduce off(default)gotoreduce onkuna — before (
option gotoreduce off)kuna — after (
option gotoreduce on)angr reference (the goal, v9.2.213)