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.
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.
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.
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.