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.
This is not the case with two other compilers i tested -
intel's icc and the microsoft's compiler.
I think that this way GCC is missing very important
and basic opportunities for optimizations.
For example there are many macros out there in the
wilderness, that heavily rely on such kind of
optimizations that disclose parentheses.
--
Summary: GCC does not disclose parentheses
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: l_belev at yahoo dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19912