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