Re: Optimizations and the -pedantic option

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

 



"Dario Saccavino" <kathoum@xxxxxxxxx> writes:

> I noticed that with the -pedantic option, the compiler was able to
> transform the recursive call in a loop, but the same optimization
> didn't happen without -pedantic. Look at the bottom of the post for
> the full assembly listings.

Interesting.  It has to do with the handling of the const variable j.
It calls the function decl_constant_value_for_broken_optimization
which has this interesting comment.

/* Return either DECL or its known constant value (if it has one), but
   return DECL if pedantic or DECL has mode BLKmode.  This is for
   bug-compatibility with the old behavior of decl_constant_value
   (before GCC 3.0); every use of this function is a bug and it should
   be removed before GCC 3.1.  It is not appropriate to use pedantic
   in a way that affects optimization, and BLKmode is probably not the
   right test for avoiding misoptimizations either.  */

The effect is that a pedantic compilation sees an add of the variable
where a non-pedantic compilation sees an add of the constant 1.  This
then leads to slightly different generated code, which causes the
non-pedantic compilation to fail to see that it can generate a tail
call.

Interestingly, this particular test case will work in 4.1.3 (if there
is a 4.1.3) because of the fix for bug 30364, which changes the
association of the generated code.

Clearly we need to actually remove
decl_constant_value_for_broken_optimization as promised in the
comment.

Ian

[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