RFC: #pragma optimization_level

Georg Bauhaus bauhaus@futureapps.de
Sat Apr 2 03:21:00 GMT 2005


E. Weddington wrote:

> What do you get if you use the C99 construct of declaring the variable 
> in the for statement? Like so:
>
> for(volatile int i = 0; i < COUNT; ++i);
>

I get the same code afaics.
In fact, I haven't been able to produce an empty loop that
isn't translated into an actual loop, volatile or not.
So maybe someone raised false alarm, and I'm guilty of
reporting it.
volatile adds instructions for copying registers to somewhere
else and back, but even without volatile the loop is made
for -O[0123]. Excerpt for x86, similarly for PPC:
(0x3b9ac9ff == 1000000000)

  20:    8b 45 fc                 mov    0xfffffffc(%ebp),%eax
  23:    40                       inc    %eax
  24:    89 45 fc                 mov    %eax,0xfffffffc(%ebp)
  27:    8b 45 fc                 mov    0xfffffffc(%ebp),%eax
  2a:    3d ff c9 9a 3b           cmp    $0x3b9ac9ff,%eax
  2f:    7e ef                    jle    20 <f+0x20>

versus

   8:    40                       inc    %eax
   9:    3d 00 ca 9a 3b           cmp    $0x3b9aca00,%eax
   e:    75 f8                    jne    8 <f+0x8>

Another issue illustrating how this was discussed in de.*
was along the lines of strlen(x) == strlen(x) being optimized
away. So it is useless in an attempt to make the computer work
unless one (a) insists on using strlen and (b) instructs the
compiler not to optimize the comparison away e.g. using a #pragma
...



More information about the Gcc mailing list