Module 15: Reaching Definition
  Lecture 30: Analysis
 


Copy Propagation

Assignment s:x=y may be eliminated if at all the places where x is used we replace x by y

  • Statement s must be the only definition of x reaching where substitution is to be made
  • On every path from s to target there are no assignments to y (additional data flow analysis needs to be done)

Algorithm: for each copy s:x=y do the following:

  1. Determine those uses of x that are reached by this definition
  2. Determine whether it is the only definition of x reaching and there is no definition of y on the path
  3. If s meets the above conditions then remove s and replace all uses of x found in (1) by y

Loop Invariant Computations

If for an assignment x=y+z all the definitions of y and z are outside loop then x=y+z is invariant of loop.
Input: A loop L with basic blocks. Assume that ud chains are available for individual statements.

  1. Mark invariant statements whose operands are all either constants or or have their reaching definitions outside L
  2. Repeat step (3) until no new statements are marked invariant
  3. Mark invariant whose operands either are constant, have all their reaching definitions outside L, or have exactly one reaching definition and that definition is a statement in L marked invariant

Performing Code Motion

  • Move an invariant statement s to pre-header if following conditions are met:
    1. The block containing s dominates all exit nodes of the nodes
    2. There is no other statement in the loop that assign to x
    3. No use of x in the loop is reached by any definition of x other than s
  • Maintaining dataflow information
    1. Ud chains: does not change by code motion
    2. Dominator information: changes by code motion; it needs to be recomputed.
  • More general code motion:
    If none of the three conditions are satisfied then for a loop invariant statement
    A=B+C define T=B+C in the pre header and replace A=B+C by A=T