TopFlow graphs and Basic BlocksGlobal Common Sub-expression Elimination

Global Common Sub-expression Elimination

  1. Now, we want to consider how to do an even better job of eliminating common sub-expressions. In particular, we want to handle control structures. So, in a piece of (meaningless) code like:

    x = y*z;
    while ( z > 0 ) {
        if ( y*z > l ) {
           z = m/n
        } else {
           z = m/n - 1;
       }
        m = m/n
    }
    

    we would like to be smart enough to realize that the boolean of the if is not a redundant common sub-expression (it will have been pre-computed on the first iteration but not on later iterations), but that the m/n after the if is redundant.

    Note, as I mentioned earlier, "global" in compiler-optmization really means one-procedure-at-a-time.

  2. The first step in the process of recognizing common sub-expressions globally is (somewhat surprisingly) a simplification of the technique for basic blocks.

    We begin by scanning the code of the procedure being processed to identify textually equivalent expressions. That is, we ignore whether the actual values of the expressions we identify might be different because they reference variables whose values have changed.

    This is not sufficient to identify CSE's, but it serves as an important first step.


Computer Science 434
Department of Computer Science
Williams College

TopFlow graphs and Basic BlocksGlobal Common Sub-expression Elimination