Prev Up
Go backward to Constant Folding and Algebraic Transformations (cont.)
Go up to Top

Value Numbering

  1. Another important optimization technique is common subexpression elimination. The goal of this optimization is to identify expressions that are guaranteed to produce identical values at runtime and arrange to only performed the associated computation once (when the first instance of the expression is encountered).

  2. This is a more interesting problem that constant folding because it involves tracking the flow of information through variables.

  3. As a result, in a general implementation of CSE (common subexpression elimination), we have to take into account assignments to variables and control flow. We will begin by restricting our attention to CSE in straight line code. Then, once the details are understood, we can see how to deal with programs (like most real ones) that include control constructs.

  4. Eliminating common sub-expressions involves two non-trivial sub-problems.

  5. The scheme we will use is called Value Numbering.

  6. The idea is to traverse the expression sub-trees of a basic block assigning an identifying number to each sub-expression. The goal is to assign the same number to all expressions we can be sure will produce the same value.

  7. The algorithm will be based on a form of table lookup. The table will associate expressions with their "value numbers". For each expression we encounter as we traverse the subtrees of a basic block we will.

  8. The trick that makes this interesting is that we will use the numbers we assign to make our table lookups efficient.

  9. We will account for assignments by changing value numbers appropriately.

  10. The hash table will map a key that uniquely identifies an expression's values to the expression's value number. The key used will depend on the form of the expression.

  11. So, to process an expression, we:

Computer Science 434
Department of Computer Science
Williams College

Prev Up