Skip to content

[AUTOMATED] fix(p3/p6): repeated pointer stores to a global made decompile time grow cubically - #820

Merged
mahaloz merged 16 commits into
mainfrom
fix/pointeestore-walk
Oct 3, 2026
Merged

mahaloz merged 16 commits into
mainfrom
fix/pointeestore-walk

Conversation

@mahaloz

@mahaloz mahaloz commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

The problem

Since #798, a function that stores a pointer to a global many times, with other pointer stores in between, decompiles much more slowly, and the gap grows faster than the function. On main:

cat > gen.py <<'PY'
import sys
n = int(sys.argv[1])
print("int *gi, *gi2;\nint big(int *p, int k, int **pp, int **pp2) {\n  int x = 0; int *q;")
for i in range(n):
    print(f"  q = p + (k + {i % 7}); gi = q; x += q[{i % 5}]; *pp = p + {i % 3}; x += gi[{i % 4}]; if (x & {1 << (i % 8)}) {{ gi2 = gi; *pp2 = q; }}")
print("  return x;\n}")
PY
python3 gen.py 600 > s600.c && gcc -O2 -c s600.c -o s600.o
/usr/bin/time -f "user %U s" kuna decompile s600.o big > /dev/null
user 37.01 s

The build before #798 takes 15.48 s, and this branch 13.37 s.

The fix

  • The store walk [AUTOMATED] fix(p3/p6): dereference a pointer stored to a global through its own variable #798 added (old_value_read_after) asked dominates() once per value of the global, each a walk up the dominator tree, and scanned every input of a join once per value the join reads. It now sets aside the values written at or after the store first, reads only the earlier values' readers, and reads each join among them once. A dominance question walks up the tree plainly for eight blocks, and only a longer walk goes through a memo for the store's block, so a long chain of blocks below the store is climbed once. One walk now costs time linear in the global's values, the earlier values' readers and the blocks of the dominator tree, but the rule pool still runs it once per reader, so the total is not linear. The order of the checks in RulePropagateCopy is main's.
  • The stores [AUTOMATED] fix(p3/p6): dereference a pointer stored to a global through its own variable #798 keeps are many COPYs of one register into one variable, and markRedundantCopies built the whole cover between every pair of them, with each step of a cover walk rescanning the block list to find a block by its index. Cover walks now find blocks through a table built once per walk. The pairs of one group share that table, the answers of long dominator walks and the variable's writes listed by block, and each pair's walk stops at the first write it meets. A cover block only grows during a walk, so the answer is the full range's.
  • Nothing printed changes. Debug builds check the dominator memo against dominates(), the block table against a scan of the block list, and each pair's shortened walk against check_copy_pair. A build that ran the old store walk beside the new one on every call agreed on all of at least 1.3 million calls, over 13 stripped binaries and 234 small objects. decompile-all of 31 stripped binaries (18,953 functions: x86-64 at O0, O2 and O2-noinline, including bash, dpkg, dash and tar; ARM firmware) is byte-identical to main (b3d0e99), as are 233 small objects built by gcc and clang at -O0 and -O2 for x86-64, aarch64, arm, i386, mips, mipsel, ppc, ppc64le and riscv64.

The tests

case N before #798 main this branch
switch, n=300 15 3.76 / 4.14 4.76 / 5.37 4.52 / 5.19
switch, n=600 7 14.99 / 15.53 25.82 / 28.06 24.93 / 28.88
generator, n=300 11 2.52 / 2.96 3.94 / 4.22 2.46 / 2.76
generator, n=600 5 14.63 / 15.03 37.72 / 38.83 12.79 / 13.53
early returns, n=300 5 2.35 / 2.60 16.75 / 18.13 4.53 / 4.96
call stores, n=300 21 0.47 / 0.48 0.60 / 0.62 0.54 / 0.57
call stores, n=600 5 1.39 / 1.44 2.17 / 2.27 1.76 / 1.79
probe fixture 11 0.95 / 1.32 4.25 / 4.93 1.72 / 1.86
bash, 11 largest functions 11 – 48.50 / 52.52 46.75 / 54.42
e2fsck, 11 largest 11 – 15.34 / 16.93 14.10 / 17.10
tar, 11 largest 11 – 31.26 / 33.71 31.18 / 34.58
dash, whole binary 15 – 6.30 / 7.46 6.13 / 7.04
rsyslogd, 10 largest 15 – 13.63 / 14.31 13.52 / 14.66

Fixes #818

🤖 Generated with Claude Code

https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt

@mahaloz mahaloz added the full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default) label Oct 2, 2026
@mahaloz
mahaloz force-pushed the fix/pointeestore-walk branch 7 times, most recently from 5e8915d to 7b61ebc Compare October 3, 2026 03:38
mahaloz and others added 16 commits October 3, 2026 06:42
old_value_read_after asked dominates() once per instance of the global,
each a walk up the dominator tree; the answers for the store's block are
now kept across the instances. A cover walk resolved every block index by
scanning the block list; FuncdataCoverCtx now builds the index table once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
…rite

markRedundantCopies built the full cover between every pair of COPYs
from one value into a high, then scanned every instance of the high. The
pairs of a group now share the dominator walks, the block table and the
high's writes indexed by block, and each range walk stops once it meets a
write. A cover block only grows during the walk, so the answer is the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
old_value_read_after scanned every input of a MULTIEQUAL once per value
of the global it read, so a join of n values cost n squared per walk; it
now collects the joins and reads each input once. The dominator memo is
a slot map, and debug builds check the shared walks against the
reference ones.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
…e the stores fixture

Unit tests check dominates_memo against dominates, add_ref_point_until
against the full cover, and redundant_in_order against the pair loop.
tests/cli/repeated-global-pointer-stores-decompile-fast.json times a
function that stores one of two pointers to a global 400 times. Chapters
03 and 06 describe the shared walks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU


RulePropagateCopy asks kuna_pointeestorekeep before kuna_globalstorekeep
for every op, so the chapter 03 note now says that instead of the marker
order this branch no longer changes. Chapter 06's paragraph on the shared
redundant-COPY walk becomes its own paragraph.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
The fixture is now the early-return shape whose decompile time #798
raised from 1.0 s to about 5 s, rather than one #798 never slowed, so
the probe's wall bound separates main from this branch by a wide margin
on both sides. It also pins the load through the global after the
pointer store, which the decompile printed as the register before #798.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
… function

The redundant-COPY helper was inserted between compare_copy_by_in_varnode's
doc comment and its function, so the helper took the comparator's header.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
…aracter limit

The probe validator rejects notes longer than 400 characters, so
make test-cli failed the probe as invalid.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
…tore walk

The store walk collected the joins of every value of the global, then
scanned each joined value's readers for the join, so a switch whose cases
each store the global conditionally, after a store of a pointer read as an
address, cost the square of the cases per asking: 5.4x main at 600 cases.
It now skips a value written at or after the store before it reads the
value's readers, and records each join with the earlier values that list it,
so no reader list is scanned twice.

dominates_memo walks up to 8 steps the plain way before it keeps answers,
and reuses its path buffer, so short dominator chains cost what dominates()
does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
…g the memo

Every dominance question in the store walk and the redundant-copy pairs
went through dominates_memo, whose call cost more than the two or three
steps most walks take: on a switch whose cases each store the global, the
store walk spent 6% more than main's per-value walk. Callers now ask
dominates_within for eight blocks first and only a longer walk reaches the
memo, which keeps the answer for every block it passes again. On that
switch the walk is now 20% faster than main's, and the issue's shapes keep
their gains.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
@mahaloz
mahaloz force-pushed the fix/pointeestore-walk branch from 7b61ebc to 6d07197 Compare October 3, 2026 06:59
@mahaloz
mahaloz merged commit 281451c into main Oct 3, 2026
9 checks passed
@mahaloz
mahaloz deleted the fix/pointeestore-walk branch October 3, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AUTOMATED] Decompile time grows superlinearly with repeated global-pointer stores since #798

1 participant