Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Jump threading
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Compiler optimization of one jump directly to a second jump}} {{Distinguish|threaded code}} {{More citations needed|date=December 2009}} {{Use dmy dates|date=December 2021|cs1-dates=y}} 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 (logic)|inverse]] of the first, it can be eliminated, or threaded through the first jump.<ref>{{Cite web|url=https://gcc.gnu.org/onlinedocs/gcc-3.4.5/gcc/Optimize-Options.html|title=Optimize Options - Using the GNU Compiler Collection (GCC)}}</ref> This is easily done in a single pass through the program, following acyclic chained jumps until the compiler arrives at a fixed point. ==Benefits== 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 (program lifecycle phase)|runtime]] [[Branch (computer science)|branch]].<ref name="redhat">{{cite web|url=https://developers.redhat.com/blog/2019/03/13/intro-jump-threading-optimizations|title=A gentle introduction to jump threading optimizations {{!}} Red Hat Developer|website=developers.redhat.com|date=13 March 2019 |access-date=2023-01-08}}</ref> ==Examples== 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: <syntaxhighlight lang="cpp" line="1"> void baz(bool x, bool y, bool z) { if (x && y) bar(); if (y || z) foo(); } </syntaxhighlight> The above can be transformed into: <syntaxhighlight lang="cpp" line="1"> void baz(bool x, bool y, bool z) { if (x && y) { bar(); goto jmp; } if (y || z) { jmp: foo(); } } </syntaxhighlight> If the first branch is taken, <code>x</code> and <code>y</code> are both [[Truth value|true]] ([[logical conjunction]]), hence evaluation of [[Expression (computer science)|expression]] <code>y || z</code> is not needed ([[logical disjunction]]). Therefore, a jump to [[Label (computer science)|label]] <code>jmp</code> is performed.<ref name="redhat"/> ==See also== * [[Switch (programming)]] * [[Spaghetti code]] ==References== {{reflist}} {{Compiler optimizations}} {{DEFAULTSORT:Jump Threading}} [[Category:Compiler optimizations]] {{Compu-sci-stub}} {{plt-stub}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite web
(
edit
)
Template:Compiler optimizations
(
edit
)
Template:Compu-sci-stub
(
edit
)
Template:Distinguish
(
edit
)
Template:More citations needed
(
edit
)
Template:Plt-stub
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Use dmy dates
(
edit
)