This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

CSE insufficiency


Hi all,

It seems that GCC does not recognize that the two expressions
`k*k+k' and `k*(k+1)' are identical (here k is int).

for example the generated code for
   int f(int k) { return (k*k+k) == (k*(k+1)); }
does the full calculation, whereas the generated code for
   int f(int k) { return (k*k+k) == (k*k+k)); }
directly returns 1

I think this is a very fundamental optimization.
I felt even more disappointed when i checked and found that other
compilers manage to do it, namely intel's icc and the microsoft's
compiler.

Regards,
Lucho


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]