TopOptimization techniques Value Numbering

Value Numbering

  1. Common subexpression elimination is an important optimization technique that we will use to explore several aspects of optimization methods.

  2. The goal of this optimization is to identify expressions that are guaranteed to produce identical values at runtime and arrange to only perform the associated computation once (when the first instance of the expression is encountered).

  3. This involves tracking the flow of information through variables.

  4. 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.

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

  6. One scheme that can be used to identify CSEs is called Value Numbering.

    The goal of this scheme will be to assign a number to each expression subtree in our program in such a way that two sub-trees will be assigned the same number only when they are guaranteed to produce the same value.

  7. We can get a sense of how the value numbering scheme works by considering a simpler scheme designed to solve only the second problem described above: the problem of identifying textually identical expression efficiently.

    The goal of this scheme will be to assign a number to each expression subtree in our program in such a way that two sub-trees will be assigned the same number exactly when they are textually identical.

  8. We will define a recursive procedure to assign these number.

  9. Unfortunately, the fact that two expressions are identical is neither necessary or sufficient evidence that they will have the same value at runtime. The problem is that the values associated with variables may change. The solution is to change the "sequence numbers" we assign to variables used as sub-expressions.

  10. The goal is to ensure that two expression are assigned the same number only if our compiler is certain that they will have the same value at runtime.

  11. We can accomplish this by changing the way we assign numbers to expressions that reference variables.

  12. This scheme will work fairly well for straight line code containing nothing but references to simple, local variables. In the real world, unfortunately, there are a few more complications to deal with.

Computer Science 434
Department of Computer Science
Williams College

TopOptimization techniques Value Numbering