4 ms·
This is also something the CPU's branch predictor can figure out and do the same optimization on. This decreases the benefit from AOT-compiled code.
by tobias3 11y ago
This is also something the CPU's branch predictor can figure out and do the same optimization on. This decreases the benefit from AOT-compiled code.
- chrisseaton 11y ago> This is also something the CPU's branch predictor can figure out and do the same optimisation on The benefit of this optimisation isn't correctly predicting the branch, which is the only thing the CPU branch predictor can do, it's removing the untaken branch from the optimisation pipeline. if (x) { y = rand(); } else { y = 14; } y * 2; In this code if x is never true then not only will the branch not taken be removed, but the code following the if statement can be optimised knowing for sure that y is always the constant 14, and then the whole thing can be constant folded.
- minikomi 11y agoWouldn't the y*2 be the first to be removed completely? :)
- Kristine1975 11y agoNot if the language uses implicit returns, as e.g. Ruby does. Then y * 2 is equivalent to return y * 2 when it is the last statement in the function.