◄ WORLD V · SONNY 5DART 164 · a helldive at the net

JUMP THREADING a jump to a jump is a jump to the end of the chain

Code generation and optimisation leave behind chains of unconditional jumps — a branch to a block that only jumps somewhere else, which only jumps somewhere else. Jump threading follows each chain to its final target and rewrites the original branch to go straight there, so control reaches the destination in one hop instead of many. The empty blocks left behind are then dead and swept away.

THE TECHNIQUE follow to the terminal, rewrite

A branch enters a chain J0→J1→J2→J3→target. Threading rewrites J0 to jump straight to the target and drops the three middlemen. Watch the chain collapse (the same follow-to-root as union-find): live demo


HISTORY & CREDIT peephole / CFG cleanup; classical

“Jump threading just deletes empty blocks.” — the deeper form threads through conditional branches too: if the path proves a condition’s value, the branch is rewritten to skip straight past the test — a special case of the same follow-the-known-target idea, and a real optimisation, not just cleanup. cited

1965 · McKeemanpeephole optimization: local rewrites over a sliding window, the family jump-threading belongs to.
classical · branch-chaining / jump-to-jump elimination is a standard CFG cleanup in every optimising compiler (no single inventor); GCC names the pass “jump threading”.
modern · SSA-based jump threading through conditionals (path-sensitive) — the form that folds a branch when the incoming edge determines it.

Following an unconditional jump chain to its terminal — branch-chain elimination — is exactly union-find’s find (dart 048): chase the next-pointer until it stops, compressing the path. Full jump threading goes further, threading through a conditional whose value the incoming edge already determines — not a plain find walk. peephole (McKeeman 1965) / classical

RECOMMEND FOR I-13 the terminal target, computed

Following the chain to its terminal — the same walk as union-find’s find — runs on the canonical compiler:

$ i13 run thread.i13 # follow next[] until a block that does not jump target = 3 -- J0 -> J1 -> J2 -> J3 -> (block 3, no jump): final target is 3 hops = 3 -- 3 middleman jumps removed; J0 now reaches 3 in one hop
Recommend: jump threading is LIT and native to I-13 — the canonical compiler follows the jump chain J0→J1→J2→J3 to its terminal target = 3 in 3 hops, by the identical follow-to-terminal recurrence as union-find’s find (dart 048) over a next[] array — this is the branch-chain-elimination case; jump threading proper also threads through determined conditionals. For an I-13 back-end emitting branches, this is the cheapest cleanup with the biggest readability win, and it composes with a bounds/cycle guard (a self-loop must not spin). The deep resonance: threading a jump chain and finding a set’s representative are the same algorithm — and both echo the corpus fold to a single ROOT.