19-10-2016, 09:12 AM
1459742667-CODEOPTIMIZATION.docx (Size: 85.74 KB / Downloads: 4)
Criteria for Code-Improving Transformations
The transformations provided by an optimizing compiler should have several properties:
1. A transformation must preserve the meaning of programs.
2.A transformation must, on the average, speed up programs by a measurable amount.
3.A transformation must be worth the effort.
Loop Optimization:
Three techniques are important:
1. Code motion – moves the code outside the loop.
2. Induction variables.
3. Reduction in Strength.
Code Motion
• It decreases the amount of code in a loop is code motion.
• It takes an expression that yields the same result independent of the number of times a loop is executed and places the expression before the loop.
• “before the loop” assumes the existence of an entry for the loop.
• Eg: evaluation of limit-2 is a loop-invariant computation in the following
while-statement:
while (i<= limit-2 )
Code motion will result in the equivalent of
t= limit-2;
while (i<=t)