This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Optimizations and the -pedantic option


"Dario Saccavino" <kathoum@gmail.com> 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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]