 <p>This is called "hoisting" <code>SlowVariabele</code> out of the loop.</p> <p>The compiler can do it only if it can prove that the value of <code>SlowVariabele</code> is the same every time, and that evaluating <code>SlowVariabele</code> has no side-effects.</p> <p>So for example consider the following code (I assume for the sake of example that accessing through a pointer is "slow" for some reason):</p> <pre><code>void foo1(int *SlowVariabele, int *result) { for (int i = 0; i &lt; *SlowVariabele; ++i) { --*result; } } </code></pre> <p>The compiler cannot (in general) hoist, because for all it knows it will be called with <code>result == SlowVariabele</code>, and so the value of <code>*SlowVariabele</code> is changing during the loop.</p> <p>On the other hand:</p> <pre><code>void foo2(int *result) { int val = 12; int *SlowVariabele = &amp;val; for (int i = 0; i &lt; *SlowVariabele; ++i) { --*result; } } </code></pre> <p>Now at least in principle, the compiler <em>can</em> know that <code>val</code> never changes in the loop, and so it can hoist. Whether it actually does so is a matter of how aggressive the optimizer is and how good its analysis of the function is, but I'd expect any serious compiler to be capable of it.</p> <p>Similarly, if <code>foo1</code> was called with pointers that the compiler can determine (at the call site) are non-equal, and if the call is inlined, then the compiler could hoist. That's what <code>restrict</code> is for:</p> <pre><code>void foo3(int *restrict SlowVariabele, int *restrict result) { for (int i = 0; i &lt; *SlowVariabele; ++i) { --*result; } } </code></pre> <p><code>restrict</code> (introduced in C99) means "you must not call this function with <code>result == SlowVariabele</code>", and allows the compiler to hoist.</p> <p>Similarly:</p> <pre><code>void foo4(int *SlowVariabele, float *result) { for (int i = 0; i &lt; *SlowVariabele; ++i) { --*result; } } </code></pre> <p>The strict aliasing rules mean that <code>SlowVariable</code> and <code>result</code> must not refer to the same location (or the program has undefined behaviour anyway), and so again the compiler can hoist.</p>