Reference:
A gentle introduction to jump threading optimizationshttps://developers.redhat.com/blog/2019/03/13/intro-jump-threading-optimizations
cmove:
https://stackoverflow.com/questions/30150274/purpose-of-cmove-instruction-in-x86-assembly
example 2
example 3
Code duplication is the key for the optimization trade-off.
gcc options:
- --param max-fsm-paths-insns=500
- --param max-fsm-thread-length
- -fno-thread-jumps
- -fdump-tree-all-details -O2
code in action
example 1
if (a > 5)
goto j;
stuff ();
stuff ();
j:
goto somewhere;
to
if (a > 5)
goto somewhere;
stuff ();
stuff ();
j:
goto somewhere;
void foo(int a, int b, int c)
{
if (a && b)
foo ();
if (b || c)
bar ();
}
to
void foo(int a, int b, int c)
{
if (a && b) {
foo ();
goto skip;
}
if (b || c) {
skip:
bar ();
}
}
void foo(int a, int b, int c)
{
if (a && b)
foo ();
tweak ();
if (b || c)
bar ();
}
to
void foo(int a, int b, int c)
{
if (a && b) {
foo ();
tweak ();
goto skip;
}
tweak ();
if (b || c) {
skip:
bar ();
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.