8.1 Comparison of Algorithms

8.2 What to Optimize

8.3 Issues in Optimization

8.4 Optimization Phases

8.5 Control Flow Analysis

8.6 Loops

8.7 Summary

Exercises

8.2 What to Optimize

We want to optimize things that happen frequently. There are two kinds of frequently: (1) how frequently a piece of code is ever written and (2) how frequently a piece of code is executed within a program.

For (1), Knuth (1971) shows empirically that simple assignment statements with one operation and one to three variables are themost often used statements:

 	A := B
 	A := A OP 1
 	A := A OP k
 	A := B OP k
 	A := B OP C
 
Here, A, B, and, C are variables and k is a constant. Follow-up studies have continued to comfirm this. It does little good to optimize for things programmers rarely write.

For (2), code in loops tends to be executed the most; thus optimizations concentrate onloops.