Skip to content

[AUTOMATED] Speed up structuring: identify only the loops the region structurer reads, and do not repeat known structurings - #1986

Merged
mahaloz merged 5 commits into
mainfrom
perf/speedback
Nov 26, 2026
Merged

mahaloz merged 5 commits into
mainfrom
perf/speedback

Conversation

@mahaloz

@mahaloz mahaloz commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Recent structuring options (condfold auto/noreturn, loopcondhoist, dedupitetail latch, returndup auto) made decompile-all up to 7.6% slower on large binaries. Most of the structuring time goes into work whose result is discarded or recomputed: the region identifier's acyclic regions, which nothing reads, and second and third structurings of a graph whose outcome is already known. This change removes that work; the output does not change.

KUNA_ACTION_PROF=prof.txt kuna decompile-all tests/hang-repro/ssh-sk-helper --jobs 1 > out.json
grep 'decompile/blockstructure$' prof.txt
before:      831.5 ms   16.30%       6866 calls  decompile/blockstructure
after:       632.5 ms   13.04%       6866 calls  decompile/blockstructure
  • The region structurer reads only the region identifier's loops (cyclic_loops). It now runs only the identifier's preprocessing and cyclic phase (KunaRegionIdentifier::compute_cyclic), and builds no identifier when regionlooprefine is off. The acyclic phase only wraps existing nodes in new regions, so every loop keeps its head, blocks and exits. It took about 60% of the identifier's time.
  • The region structurer fails on about four structurings in five, and its result depends only on the block graph, the loop-condition rule and the o0jumps gate. Within one ActionBlockStructure run, a structuring of the same graph after such a failure goes straight to CollapseStructure: the condfold structuring without the relaxation, and the loopcontinue auto structuring with the record back on.
  • When the loopcondhoist rule wins over the rule-free structuring, the first collapse is saved aside and put back. It is no longer collapsed a third time. A check that both seedings map every block to the same copy guards this.

decompile-all --jobs 1, user+sys CPU, minimum of 4 interleaved runs:

binary (decbench) before these options (af36b9e) main this PR PR / before
bash, O2-noinline 34.76 s 37.39 s (1.076) 35.19 s 1.012
sshd, O0 23.68 s 24.30 s (1.026) 23.31 s 0.984
sshd, O2-noinline 21.77 s 22.29 s (1.024) 21.80 s 1.001
bash, O0 35.16 s 35.25 s (1.003) 33.81 s 0.962
ls, O2-noinline 4.94 s 5.12 s (1.036) 4.79 s 0.970

Tests: a unit test checks that compute_cyclic finds the same loops as compute on three graphs with nested and multi-exit loops. The decbench corpus (35,197 O2 and 34,473 O0 functions) prints byte-identical C before and after. tests/stages/kuna-chainfold.xml also pins the comma-operand form of a chain with a store between its calls: if ((!v1) && (order = 1, v1 = put(..), !v1)) under condfold auto, nested ifs under noreturn. The chain-fold round trip runs that function too.

Model: anthropic/claude-opus-5-5

🤖 Generated with Claude Code

https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU

mahaloz and others added 5 commits November 26, 2026 05:59
[AUTOMATED] Keep the first loop-condition collapse instead of a third run,
skip a region structuring already known to fail within one apply, and run
only the cyclic phase of the region identifier the region structurer reads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Spec prose for chapters 07 and 08, and a unit test that the
cyclic-only identification yields the same loops as the full analysis.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] chainfold.c gains commit(), appended after main so no existing
function moves: `order = 1` sits between two put() calls whose failures share
one ordinary block. condfold auto prints it as a comma operand of the
condition, noreturn as nested ifs; the round trip runs it too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
@mahaloz
mahaloz merged commit 477cb29 into main Nov 26, 2026
9 checks passed
@mahaloz
mahaloz deleted the perf/speedback branch November 26, 2026 07:17
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