| Table of Contents | Previous Slide | Next Slide |
Software Development in the UNIX Environment
Optimizing Your Code
How Code Gets Optimized
Classical Optimizations: (taken from High Performance Computing
by Kevin Dowd published by O'Reilly )
| Type of Optimization | Unoptimized Code | Optimized Code |
| Copy propagation | x=y z=1+x |
x=y z=1+y |
| Constant folding (evaluates at compile time |
integer i,k parameter(i=100) k=200 j=i+k |
j is a constant as well as i,k |
| Dead code Removal | Program main i=2 write(*,*) i stop i=4 write(*,*) i end |
Program main i=2 write(*,*) i stop |
| Strength reduction | y=x**2 j=k*2 |
x*x k+k |
| Variable renaming | x=y*z; q=r+x+x; x=a+b; |
x0=y*z; q=r+x0+x0; x=a+b; |
| Common Subexpression Elimination | d=c*(a+b); e=(a+b)/2; |
temp=a+b; d=c*temp; e=temp/2; |
| Loop Invariant Code Motion | do 10 i=1,n a(i)=b(i)+c+d e=g(k) 10 continue |
temp=c+d do 10 i=1,n a(i)=b(i)+temp 10 continue e=g(k) |