Module 12: View
Lecture 24: Code Optimization
Code Optimization
int a,b,c,d
c = a+b
d = c+1
ldw a,r1
ldw b,r2
add r1,r2,r3
stw r3,c
ldw c,r3
add r3,1,r4
stw r4,d
add r1,r2,r3
add r3,1,r4
source code
naive sparc code
10 cycles
optimized code
2 cycles
Most Important Optimizations
Loop Optimizations
Moving loop invariant computations
Simplifying or eliminating computations on induction variables
Global register allocation
Instruction scheduling
Some optimizations may be relevant to a particular program and may vary according to the structure and details of the programs
A highly recursive program may benefit from tail call optimization
A program with few loops and large basic blocks may benefit from loop distribution
In-lining may decrease call over heads; in-lining may increase the code size and may have negative effect on performance by increasing cache misses