If components of an expression are duplicate expressions, code them either at the left end of the expression or within parentheses. For example:
a = b*(x*y*z); /* Duplicates recognized */ c = x*y*z*d; e = f + (x + y); g = x + y + h; a = b*x*y*z; /* No duplicates recognized */ c = x*y*z*d; e = f + x + y; g = x + y + h;
When components of an expression in a loop are constant, code the expressions either at the left end of the expression, or within parentheses. If c, d, and e are constant and v, w, and x are variable, the following examples show the difference in evaluation:
v*w*x*(c*d*e); /* Loop invariant expressions recognized */ c + d + e + v + w + x; v*w*x*c*d*e; /* Optimization required for constant */ v + w + x + c + d + e; /* expressions to be recognized */
For integer expressions, the loop invariant expression will be recognized if -O is specified. For floating-point expressions, the loop invariant expression will be recognized if -O3 is specified.
Program Optimization with IBM C and C++ Compilers
Writing Optimized Code... Overview Variables Pointers Functions Function Arguments Critical Loops Conversions Arithmetic Conversions Inlined Components