Jump threading

compiler optimization of one jump directly to a second jump

Uses your system voice; voice and rate in settings.

≈ 3 min read

Cite, export and learn8 citation formats · 8 exports · lesson and quiz

Names in other languages

  • Englishjump threading
  • 中文跳转线程

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

In computing, jump threading is a compiler optimization of one jump directly to a second jump. If the second condition is a subset or inverse of the first, it can be eliminated, or threaded through the first jump.[1] This is easily done in a single pass through the program, following acyclic chained jumps until the compiler arrives at a fixed point.

Benefits

edit edit source

The primary benefit of jump threading is the reduction of the amount of dynamically executed jumps. This makes way for further optimizations as there is a decrease in the number of conditionals, which will improve performance. On average one can expect 2-3 instructions being omitted as a result from a successful removal of a runtime branch.[2]

Examples

edit edit source

The following pseudocode demonstrates when a jump may be threaded.

10. a = SomeNumber(); 20. IF a > 10 GOTO 50 ... 50. IF a > 0 GOTO 100 ...

The jump on line 50 will always be taken if the jump on line 20 is taken. Therefore, for as long as line 100 is within the reachable range of the jump (or the size of the jump doesn't matter), the jump on line 20 may safely be modified to jump directly to line 100.

Another example shows jump threading of 2 partial overlap conditions:

void baz(bool x, bool y, bool z) { if (x && y) bar(); if (y || z) foo(); }

The above can be transformed into:

void baz(bool x, bool y, bool z) { if (x && y) { bar(); goto jmp; } if (y || z) { jmp: foo(); } }

If the first branch is taken, x and y are both true (logical conjunction), hence evaluation of expression y || z is not needed (logical disjunction). Therefore, a jump to label jmp is performed.[2]

See also

edit edit source

References

edit edit source
  1. ^ "Optimize Options - Using the GNU Compiler Collection (GCC)". Wikipedia revision 1337508978, retrieved 2026-11-20
  2. ^ a b "A gentle introduction to jump threading optimizations | Red Hat Developer". developers.redhat.com. 2019-03-13. Retrieved 2023-01-08. Wikipedia revision 1337508978, retrieved 2026-11-20
Compiler optimizationsBasic block Loop Data-flow
analysis
SSA-based Code generation Functional Global Other Static analysis

Text derived from https://en.wikipedia.org/w/index.php?oldid=1337508978 under CC BY-SA 4.0; modifications have been made.

Words in each sectionExamplesExamplesExamples: 176 words176BenefitsBenefitsBenefits: 62 words62See alsoSee alsoSee also: 7 words7
Words in each section. Measured from the stored article body; sections below the minimum are not plotted.

Provenance

snapshot jump-threading-715077-6b25fb857ef13907 · hash 6b25fb857ef139072e7aab59d5551a6102eff9b694a7d5e22537c1129bb8b071 · captured 2026-02-09 · ledger · version history

Cite this page as: encyclopegia.org, “Jump threading”, snapshot jump-threading-715077-6b25fb857ef13907. https://encyclopegia.org/a/jump-threading