Re: Optimizer problem with repeated loops over memory

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

 



On Tue, May 13, 2008 at 9:13 PM, Nick Spence <nick.spence@xxxxxxxxxxxxx> wrote:
>        addr = 0;
>        for (i = 0; i < 16; i++) *(addr++) = 0;

My guess is that GCC knows that your program is invoking nasal demons
(undefined behaviour from dereferencing a null pointer) and you're
lucky it's even generating code for the second loop at all!

I got a conditional jump by replacing your initialization of addr with:

  asm("" : "=g" (addr) : "0" (0));

That should make the NULL-ness of addr invisible to GCC.  If you can
(and maybe your environment doesn't allow [much] initialized data),
you could also declare addr as a global variable initialized to zero.
Then hope that link-time optimization doesn't see through your
trickery again in a few months/years when it becomes mainstream!

[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