I get one question when I read Lecture 11, Common Subexpression Elimination, of Advanced Compilers course of umass amherst.
The question is, on page 12 in Lecture 11, it illustrates that value numbering can't eliminate all subexpressions.
read(i);
l = 2*i;
if(i > 0) goto L1;
j = 2*i;
goto L2;
L1: k = 2*i;
L2:
The explanation is: l’s value is not always equal to j’s or k’s value
What's puzzled me is, all (l / j / k)'s values depend on 2*i , i's value numbering should be the same in all basic blocks as there's no any assignment or re-definition for i in exampled code snippet. Is it correct?
If it's correct, 2*i will get the same value numbering too and the redundant 2*i computations for j and k can be eliminated successfully.
Do I make any mistake for the illustration? please help me to address it if you found.