Loop optimization

LOOP OPTIMIZATION:


Invariant code: The code which reside in a loop and computes same value at each iteration is known as invariant code. This code can be moved out of the loop to compute once, other than at each iteration, to reduce the computation time.


Induction analysis: A variable is called an induction variable if its value gets changed within the loop by a loop-invariant value.

Strength reduction: It means reducing the consumption of CPU cycles, time  and memory, by replacing the strength consuming expressions with less or cheaper expressions without compromising the output of the expression.


unoptimized code
repeat
S1;
i := j;
s2
until p;
optimized code
i := j;
repeat
Sl;
s2
until p;

Related topics

Professor Jayesh video tutorial

Please use contact page in this website if you find anything incorrect or you want to share more information about the topic discussed above.