![]() | ![]() | ![]() | Value Numbering |
x = a + b; y = c + d; a = e; z = a + b; w = b + y; v = b + c + d;The two occurences of "a+b" are not common subexpressions because the value of a may change between the evaluation of the first and second copies of the expression. On the other hand, the last two expressions, "b + y" and "b + c + d" can be identified as common subexpressions even though they are not textually identical because they are guaranteed to produce identical values.
x = 1 + y; a[y + 1] = a[x] + 1
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.
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.
x := E
x = a[i] + z y = k; z = a[i] + zwe certainly would expect to be able to identify "a[i] + z" as a common sub-expression and eliminate the evaluation of the second copy of the expression (just using the value of x insead).
x = a[i] + z a[k] = k; z = a[i] + zEven though the value of k is likely to be different from the value of i, our value numbering scheme doesn't provide a way to know this for sure. It only tells us when two variables definitely have the same value, not when they definitely are different. So, we would have to be careful and assume that the second copy of "a[i] + z" might produce a different value from the first copy.
![]() | ![]() | ![]() | Value Numbering |