Loop-invariant code motion: Difference between revisions

Content deleted Content added
m And still can't do an em dash properly
m Explain why 6 * i is not necessary as a temporary
Line 24:
x = y + z;
t1 = x * x;
for (i = 0; i < n; i++i) {
a[i] = 6 * i + t1;
}
</source>
 
This code can be optimized further. For example, [[strength reduction]] could remove the two multiplications inside the loop (<code>6*i</code> and <code>a[i]</code>), and [[induction variable]] elimination could then elide <code>i</code> completely. Since <code>6 * i</code> must needs be in lock step with <code>i</code> itself, there is no need to have both.
 
==See also==