Two types of loop optimizations are done by SDCC loop invariant
lifting and strength reduction of loop induction variables.
In addition to the strength reduction the optimizer marks the induction
variables and the register allocator tries to keep the induction variables
in registers for the duration of the loop. Because of this preference
of the register allocator, loop induction
optimization causes an increase in register pressure, which may cause
unwanted spilling of other temporary variables into the stack
/ data space. The compiler will generate a warning message when it
is forced to allocate extra space either on the stack or data space.
If this extra space allocation is undesirable then induction optimization
can be eliminated either for the entire source file (with --noinduction
option) or for a given function only using #pragma noinduction.
Loop Invariant:
for (i = 0 ; i < 100 ; i ++)changed to
f += k + l;
itemp = k + l;As mentioned previously some loop invariants are not as apparent, all static address computations are also moved out of the loop.
for (i = 0; i < 100; i++)
f += itemp;
for (i=0;i < 100; i++)changed to
ar[i*5] = i*3;
itemp1 = 0;The more expensive multiplication is changed to a less expensive addition.
itemp2 = 0;
for (i=0;i< 100;i++) {
ar[itemp1] = itemp2;
itemp1 += 5;
itemp2 += 3;
}