Repository navigation
dedupitetail: merge duplicated if/else tails (true_1804 usage) - #104
Merged
Merged
Conversation
New S8 structuring pass `ActionDedupIteTail` (option `dedupitetail`, ElementId
4109, default-OFF) — the inverse of the SAILR duplication passes
(gotoreduce/crossjumprevert/taildup). kuna inherits Ghidra's collapse-based
structurer, which clones a basic block reachable from both arms of an if/else
into each arm instead of converging the two predecessors onto one copy. This
pass detects when both arms of a 3-component BlockIf share a maximal common
PREFIX or SUFFIX of leaf blocks that emit identical C and hoists that shared run
out of the if (prefix before, suffix after), emitting one copy instead of two.
Equivalence is exact-or-decline: same printed-op sequence, constants matched by
value, named storage by location, call targets by resolved callee (op-wise via
get_call_specs_index), block-local unique temps paired positionally; STORE and
unresolvable operands decline. The transform is a pure print-tree edit (no p-code
cloned, SSA/def-use untouched): a prefix hoist is unconditionally sound (both
arms run it first); a suffix hoist is gated on both arms' divergent middles
falling through to it. Bounded (<=8 leaves, <=64 ops/leaf) and only flat
unlabelled leaves are merged. Surgery helpers kuna_hoist_ite_{prefix,suffix} in
block.rs, with unwrap_singleton_clause to avoid the degenerate 1-element BlockList
the PrintC emitBlockLs path double-emits.
Registered everywhere: stages.toml (settable -> 64), options.rs
KUNA_OPTION_NAMES, architecture flag/ctor/reset/parse/seam-copy, seams.rs,
universalaction (after crossjumprevert). Catalog/count fixtures bumped
(catalog_bytecompat 64, kuna_stages settable_count_is_64, verify_w8 265 leaves +
order, stage_catalog.json regenerated, list_action oracle, kuna-catalog.xml
#5/#6/#7/#9). docs/assertions.md regenerated; `kuna catalog --check` OK.
Two-pass stage test tests/stages/ghangr-true-1804-dedup-ite-tail-8a690c.xml
(minimised x86-64 reproducer, the who.o/morton convention): off clones the shared
epilogue into both arms (2 copies), on merges to 1 and logs the dedup.
Gates: `make test` PARITY OK 675/675 (byte-identical, default-OFF);
`make test-stages` PARITY OK 233/233. Speed: no measurable change (~0.20s on
usage off vs on). NOTE: the target true_1804::usage tail is sub-block-entangled
(the online-help printf shares a bblock with the setlocale condition test), so it
needs the full label-convergence transform and is out of scope for this bounded
leaf hoist — the pass is sound/general and the stage test uses the reproducer.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
The documentary count comment lagged the actual table (40 stage-model knobs after dedupitetail; settable=64). No asserted value changes. 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 26, 2026
Union both opt-in settables atop main: dedupitetail (4109, #104) + unrolledguard (no ElementId, #105). Resolved by UNION (no registration dropped): - stages.toml: 65 settables, 98 surfaces; header counts updated - kuna_stages/tests.rs: settable_count_is_65, surface_count_is_98, 64 trailing commas in the static catalog - catalog_bytecompat.rs: 65 "option" rows - xml.rs corpus count: 155 (83 datatests + 72 stage testcases) - kuna-catalog.xml provenance: #6 source_decompiler angr=24, #7 structure-recovery=13 (+dedupitetail), #8 opt-in-tool=12 (+unrolledguard), #5/#9 use_when/change_kind max bumped 65->66 (65 settables + returnpair dup) - baseline-stages.json + assertions.md regenerated (235/235) Gates: catalog --check OK; make test PARITY OK 675/675; make test-stages PARITY OK 235/235; make rust-test green. 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.
dedupitetail— merge duplicated if/else tails (angr ITE region-dedup)Implements proposal #53. A new S8 structuring pass
ActionDedupIteTail(option
dedupitetail, ElementId 4109, default-OFF) — the inverse of theSAILR duplication passes (
gotoreduce/crossjumprevert/taildup).The gap
kuna inherits Ghidra's collapse-based structurer, which, when a basic block is
reachable from both arms of an
if/else, clones it into each arm instead ofconverging the two predecessors onto one copy. angr emits each shared continuation
once. So kuna over-duplicates a shared if/else tail and the readability win is to
merge the identical copies.
What it does
For every 3-component
BlockIf, find the maximal common prefix or suffix ofleaf blocks that emit identical C and hoist that shared run out of the
if(prefixbefore it, suffix after), emitting one copy instead of two:
value; named storage by location; call targets by resolved callee
(
get_call_specs_index, not the per-call-site fspec index); block-localuniquetemps paired positionally.
STOREand any unresolvable operand decline.prefix hoist is unconditionally sound (both arms run it first); a suffix hoist is
gated on both arms' divergent middles falling through to it.
(never a nested if/loop or a goto/label block). Surgery helpers
kuna_hoist_ite_{prefix,suffix}inblock.rs, withunwrap_singleton_clausetoavoid the degenerate 1-element
BlockListthePrintC::emitBlockLspathdouble-emits.
Before / after (the stage-test reproducer
g)The two arms each run a divergent guard then call the SAME shared epilogue
shared(y)in its own block (the ISC-condensed shared-tail shape):shared(a1): 2 copies -> 1; one fewer cloned call.Scope note (the original target)
The proposal's target
true_ubuntu1804::usagehas its duplicationsub-block-entangled — the online-help
__printf_chkshares a basic block withthe
setlocalecondition test, so the shared code is the condition block of an if,not a hoistable leaf. Fully matching angr there needs the deeper label-convergence
transform (angr threads
LABEL_4018e8/LABEL_401822), which is genuinely LARGE andbeyond a sound bounded leaf hoist. This PR ships the sound, general subset (prefix +
suffix leaf hoisting) the proposal's plan step 1 sanctions, with the stage test on a
minimised x86-64 reproducer — exactly the
who.o/mortonSAILR-family convention.Registration / tests
Registered everywhere:
stages.toml(settable -> 64),options.rsKUNA_OPTION_NAMES, architecture flag/ctor/reset/parse/seam-copy,seams.rs,universalaction(aftercrossjumprevert). All count fixtures bumped(
catalog_bytecompat64,kuna_stagessettable_count_is_64,verify_w8265leaves + order,
stage_catalog.jsonregenerated,list_actionoracle, corpus count154,
kuna-catalog.xml#5/#6/#7/#9).docs/assertions.mdregenerated;kuna catalog --checkOK.Two-pass stage test
tests/stages/ghangr-true-1804-dedup-ite-tail-8a690c.xml: off clones the epilogueinto both arms (2), on merges to 1 and logs the dedup.
Gates
make test— PARITY OK 675/675 (byte-identical; the option is default-OFF).make test-stages— PARITY OK 233/233 (incl. the 3 new assertions).make rust-test— green (count fixtures updated).usage, off vs on) — the pass isO(structured-nodes x bounded-leaf-eq).
docs/baseline.jsonis untouched.🤖 Generated with Claude Code
https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac