next up previous
Next: Global Recycling of Available Expressions Up: Compiler Theory: Code Optimization Previous: Global Live Variable Analysis

Global Copy Propagation and Dead Code Elimination

KEY IDEA. With the data-flow sets inR(B) and inC(B) computed in the previous sections we can consider global copy propagation and dead-code elimination across basic blocks.


ALGORITHM. For each copy statement S: b := c in the program do

  1. Find all uses of b in some statement S'. That is, find every reference to b in a statement S' of block B such that no redefinitions of b or c appear between entry(B) and S'.
  2. For each such use of b where, furthermore, S $ \in$ inC(B), replace b by c.
  3. if we can do this replacement in all the above cases, then remove the copy statement S: b := c.


EXERCISE. Apply the previous algorithm to Figure 10.

Figure 10: A control flow graph.
\begin{figure}\htmlimage
\centering\includegraphics[scale=.6]{ControlFlowGraph7.eps}
\end{figure}


next up previous
Next: Global Recycling of Available Expressions Up: Compiler Theory: Code Optimization Previous: Global Live Variable Analysis
Marc Moreno Maza
2004-12-02