News for hackers. Stuff that matters.
Re:Jump Threading by userbinator on Thursday October 29, 2015 @01:57AM (#10469515)
at the expense of code size. For hardware with branch prediction, speculative execution, and prefetching, this can greatly improve performance

...up to the point when other code starts getting pushed out of the cache. This seems like an odd statement to make, since the transformation appears to be, like loop unrolling, of most benefit to processors which do not have features like branch prediction/OoO and thus very strongly prefer to execute "straight-line" code with as few branches as possible. Examples include early RISCs and the Pentium 4.

Also, the article describes something slightly different from both the GCC manual and the Wikipedia article - these describe an optimisation which rewrites chains of jumps into direct ones and does not involve duplicating code.

Re:Jump Threading by qznc on Thursday October 29, 2015 @04:12AM (#10469762)
Originally in libfirm it was called "partial conditional evaluation" and then was renamed [0] into "path-sensitive jump threading".

[0] http://pp.ipd.kit.edu/git/libfirm/commit/?id=d1c902c90f627d1...

Re:Jump Threading by qznc on Thursday October 29, 2015 @05:56AM (#10469998)
If you convert branches into straight jumps, then branch prediction cannot be wrong anymore. Thus improvement.

Without branch prediction and speculative execution, a branch and a jump instruction should be equivalent, hence no improvement. However, it should still yield an improvement because there is no condition to evaluate anymore, hence less code.

Re:Jump Threading by heinrich5991 on Thursday October 29, 2015 @06:55AM (#10470143)
>If you convert branches into straight jumps, then branch prediction cannot be wrong anymore. Thus improvement.

It's more like: No degradation. And there might be performance degradation by the additional memory use.

Re:Jump Threading by UniQP on Thursday October 29, 2015 @08:54AM (#10470573)
Jump threading can also enables additional optimizations. For instance, if you apply jump threading to

int eight(int a) { int b; if (a) { b = 1; } else { b = a; } b += 3; if (a) { return b + b; } else { return b + 5; } }

you duplicate the "b += 3;" but both branches can be optimized afterwards. In fact, the function always returns 8.

Re:Jump Threading by qznc on Thursday October 29, 2015 @08:19AM (#10470424)
I don't understand what you mean with "no degradation".

A branch predictor can be wrong. A simple jump is like the branch predictor is always right. Thus, the code might run faster.

Re:Jump Threading by heinrich5991 on Thursday October 29, 2015 @09:13AM (#10470687)
Yes. But a branch predictor can also be right every time. Or it could be right so often that it is better than the larger memory footprint of the program.
Re:Jump Threading by rkangel on Thursday October 29, 2015 @05:31AM (#10469937)
It sounds like it would have been more precise to say "for hardware that relies on branch prediction, speculative execution, and prefetching".