------- Additional Comments From joseph at codesourcery dot com 2005-02-11 21:34 ------- Subject: Re: New: GCC does not disclose parentheses
On Fri, 11 Feb 2005, l_belev at yahoo dot com wrote: > GCC generates different codes for the both functions: > int f1(int k) { return k*k+k; } > int f2(int k) { return k*(k+1); } > > also the generated code for, say '(k*k+k) + (k*(k+1))' > calculates the two parts independently and then sums them, > whereas the code for '(k*k+k) + (k*k+k)' just calculates > k*k+k once and then doubles it. Note that the first expression can involve undefined behavior when the second doesn't, so transformations between these forms would be invalid with -ftrapv and until we have internal overflow flags on expressions we could only transform in one direction without -fwrapv. (Consider k == -46341 with 32-bit int. The first expression involves signed integer overflow, undefined behavior in ISO C which needs a trap with -ftrapv, while the second doesn't.) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19912