![]() | ![]() | ![]() | Value Numbering (cont.) |
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.
This value number associated with an array should clearly be changed when we process an assignment such as
a = new int[ size ];or
a = b;but to play it safe, we will also change it when we encounter
a[i] = n;
a = b;points up other horrible issues. Suppose we have to deal with code that looks like:
a = b; x = a[i] + z b[k] = k; z = a[i] + zBecause "a" and "b" now refer to the same array, the assignment to b[k] may change a[i]. Once again, we cannot safely treat a[i] + z as a CSE. Somehow, when we process an assignment that changes b, we have to know enough to change the value number associated with a!
We can either do much more sophisticated analysis to estimate the set of variable that may refer to the same array as a name like "b" and change all the value numbers in this set when we assign to b, or we can just update the value numbers of all array variables that refer to arrays of the same type as b.
![]() | ![]() | ![]() | Value Numbering (cont.) |