Repository navigation
Conversation
tail_dup admitted any shared tail of at most six statements, including one
that contains an `if` or a loop, so a decision the program makes once was
printed at every place that reaches it: `if (!color) REMOVE_COLOR(); return`
four times in every BSD `RB_REMOVE`, a `do { } while (busy)` wait eight times
in libopencm3's `sdram_command`. angr's ReturnDuplicatorHigh, which the module
cites, duplicates only a return-only block.
Both admission points -- the gotoless split and the goto-driven clone -- now
require the region to be straight-line when it would end up in more than one
place. A single-reference region that is moved rather than copied is exempt.
The stack-protector check is the one branch that does not count: it is the
compiler's, it precedes every return of a protected function, and the last
cleanup pass removes it. `stack_protector_pass_arm` recognises it in the
two-armed shape it has when tail_dup runs; the existing predicate matches
only the settled one-armed guard. Without this exemption the same rule loses
25-27 perfects per config, all of them canary epilogues.
Measured on the full local DecBench configs against main, same rows:
unoptimized distance 394,148 -> 392,704, perfect 12,976 -> 12,994 (18 new,
0 lost); -O2 621,358 -> 619,683, perfect 7,378 -> 7,379 (1 new, 0 lost).
Sample-set gate: perfect 67 -> 67, distance 7,603 -> 7,611 (one row).
In the changed functions gotos rise (1,429 -> 1,695 and 1,732 -> 2,063) and
lines fall (39,192 -> 37,701 and 32,727 -> 31,052).
Proposal: docs/proposals/2026-11-16-tail-dup-straight-line-tails.md
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
This branch has not been deployed
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.
What
tail_dupcopies a function's shared tail into each place that reaches it. It admitted any tail of at most six statements, including one that contains anifor a loop, so a decision the program makes once was printed at every site:RB_REMOVE(openssh, 16 rows):if (!color) REMOVE_COLOR(); return old;four times. The source has it once, undercolor:.ifs_firstchar:if (lenp) *lenp = len; return ret;at the end of both arms. The source has it once, after theif/else.sdram_command(-O2): ado { } while (busy)wait, a store and thereturneight times. The source has it once, after theswitch.A reader who meets the same
iffour times has to compare the copies to learn they are one piece of code. A compiler merges a function'sreturn; it does not merge four separately writtenifs. angr'sReturnDuplicatorHigh, which the module cites as its reference, duplicates only a return-only block.Change
Both admission points (the gotoless split and the goto-driven clone) require the region to be straight-line when it would end up in more than one place. A single-reference region that is moved, not copied, is exempt.
One branch does not count: the stack-protector check. It is the compiler's, it precedes every
returnof a protected function, and the last cleanup pass removes it.stack_protector_pass_armrecognises it in the two-armed shape it has whentail_dupruns. Without this exemption the same rule loses 25-27 perfects per config, all of them canary epilogues (measured; table in the proposal).Measurement
Full local DecBench configs against
main(1c10edab0), same rows, caches off:-O0main-O0this PR-O2main-O2this PR-O0) and 1,404,115 -> 1,404,001 (-O2); compilable count unchanged.print_list, 105 -> 113). On the scored rows this is a small loss; the gain is on rows the benchmark does not score.-O0, 228 at-O2): lines 39,192 -> 37,701 and 32,727 -> 31,052;gotos 1,429 -> 1,695 and 1,732 -> 2,063. Each addedgotoreplaces a copy of a tail that decides something.Rows that got worse
Read, not just counted. Four kinds:
gotoand the output now does too, but the distance rises:sshauthopt_merge(+24; the output now has the source'salloc_fail:/fail:pair),get_token,globextend.ifthe structurer did not recover, so the single copy sits behind agoto:f_open,echo::main,realpath::main.BZ_SETERRinBZ2_bzWrite, +52). The old copies matched it.if (!diff) { return v; } __stack_chk_fail();, is printed once behind agotoinstead of at every return (zlibinflate,start_header,prime2_p,print_list). At-O2the same shape improves 47 rows and worsens 12.Not in this PR
if (!diff) { return v; } __stack_chk_fail();survives to the output onmaintoo: the stack-protector pass drops the guard only when the handler call is inside theif.mainalready emits in 74 / 118 functions; three more here (sdram_command).pmUpdateState,config_in_out_int,dir_allocin crazyflie). With this change on top of fix(normalize): a flag is a snapshot; SLEIGH's temporary flags are flags #900 those three print as onmain. The combination was checked on those functions only, not swept.Checks
cargo nextest run -p fission-midend-structuring -p fission-pcode, debug and--release: pass.cargo clippy --workspace --locked -- -D warnings -A clippy::style -A clippy::complexity,cargo fmt --all --check,scripts/check/owner_boundaries.sh: pass.Proposal:
docs/proposals/2026-11-16-tail-dup-straight-line-tails.md🤖 Generated with Claude Code