next up previous contents index
Next: 8.1.2 Dead-Code Elimination Up: 8.1 Optimizations Previous: 8.1 Optimizations   Contents   Index


8.1.1 Sub-expression Elimination

The compiler does local and global common subexpression elimination, e.g.:

i = x + y + 1;  
j = x + y;
will be translated to

iTemp = x + y;  
i = iTemp + 1;  
j = iTemp;
Some subexpressions are not as obvious as the above example, e.g.:

a->b[i].c = 10;  
a->b[i].d = 11;
In this case the address arithmetic a->b[i] will be computed only once; the equivalent code in C would be.

iTemp = a->b[i];  
iTemp.c = 10;  
iTemp.d = 11;
The compiler will try to keep these temporary variables in registers.



2008-12-05