User: Password:
Subscribe / Log in / New account

Is this an useful optimization ??

Is this an useful optimization ??

Posted Apr 18, 2008 21:22 UTC (Fri) by mikov (subscriber, #33179)
In reply to: Is this an useful optimization ?? by ibukanov
Parent article: GCC and pointer overflows

Exactly my point. It is not easy to imagine a case where this is a _desirable_ optimization.
It is either a bug, which should be warned, or it is deliberate. Either way the compiler
should not remove the code!

I imagine however that the general assumption "int + positive_value is always greater than
int" may be useful for complex loop optimizations and the like. It probably allows to
completely ignore integer overflow in cases like this "for (int i = 0; i < x; ++i ) {...}". 

(Log in to post comments)

Is this an useful optimization ??

Posted Apr 18, 2008 22:29 UTC (Fri) by nix (subscriber, #2304) [Link]

That's equally useful for pointer arithmetic. Think arrays, strings, 
pointer walks, even things like Floyd's algorithm (smart optimizers can 
even spot the relationship between the tortoise and the hare: allowing for 
the hare to wrap around would ruin that).

Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds