Loop optimization by invariant code motion means moving calculations or code inside a loop that do not change during the loop outside it. For example, in a loop running three times, if a calculation like 5 times 2 is done inside each iteration, it can be moved before the loop to run once. This saves time because the calculation is constant. The execution table shows that before optimization, the expression is computed every iteration, but after optimization, it is computed once and reused. Variables like 'i' change each iteration, but 'x' remains constant after moving outside. This optimization does not change the output but makes the loop faster. If the code depends on the loop variable, it cannot be moved outside safely.