Loop Invariant Code Motion - am I missing something?
You can also replace with

if (loop_condition) {
    loop_invariant_code
    do {
        loop_body
    } while (loop_condition)
}


With all he precautions of course. That makes the loop a bit simpler, and saves one test of the condition. And because you have no extra evaluations of loop_condition, this should be correct even if loop_condition has side effects. 

And in the first example starting with i = 10 you should be able to optimise the first loop condition away. 

But absolutely, you cannot just move code with side effects out of a loop, and you should be careful moving code without side effects, in case the loop is not executed and the moved code just wastes time. This more critical in languages that do overflow checks, so adding a+b can actually have a side effect on overflow.

Note: The wikipedia article also mentions strength reduction (for example, instead of calculating i*6, set tmp = 0 before the loop starts, and increase tmp by six at each iteration). Setting tmp = 0 would also only be executed if the loop condition is tested once.