Re: Is it OK that gcc optimizes away overflow check?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 26-07-2011 18:37, Andrew Haley wrote:
On 07/26/2011 11:35 AM, Andrew Haley wrote:

Consider

   for (i = 0; i<  limit; i++)
     f(i * 2);

which can be rewritten to

   int tmp = limit * 2;
   for (i = 0; i<  tmp; i += 2)
     f(i);

I tried your example. It doesn't make an induction variable because it can do i*2 with the LEA instruction at no extra cost. With i*11 it makes two counters:

for (i=0, k=0; i<limit; i++, k+=11) f(k);

I can't make it do what we both expect unless limit is a compile-time constant:

for (k=0; k<limit*11; k+=11) f(k);

The reason I'm asking is that it would be interesting to know whether it is better to use signed or unsigned integers in order to get the best optimizations. I would publish that in my optimization manuals ( http://www.agner.org/optimize/#manuals )

Can you give any examples where optimization is better for signed integers than for unsigned, or vice versa?


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux