Optimization
Optimization
Optimizations
Compiler Code Optimizations
Introduction
• Optimized code
Executes faster
efficient memory usage
yielding better performance.
Code hoisting
• Moving computations outside loops
• Saves computing time
Compiler Code Optimizations
Code hoisting
• In the following example (2.0 * PI) is an
invariant expression there is no reason to
recompute it 100 times.
DO I = 1, 100
ARRAY(I) = 2.0 * PI * I
ENDDO
t = limit-2;
while (i <= t)
do {loop code}
Compiler Code Optimizations
Conclusion
• Compilers can provide some code
optimization.
• Programmers do have to worry about
such optimizations.
• Program definition must be preserved.