I just spent a couple of hours looking into what turned out to be an
issue with decl_constant_value_for_broken_optimization, and I wanted
to record the notes.


The function was introduced here:
    http://gcc.gnu.org/ml/gcc-patches/2000-10/msg00649.html

At the time Joseph added this 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.  */


Needless to say, the function was not removed before gcc 3.1, and
indeed has not yet been removed seven years later.  As the comment
says, the existence of this function means that in some cases we
generate different code merely because -pedantic is specified.  This
led to a recent question on gcc-help.


Joseph's patch removed the checking of pedantic from
decl_constant_value.  I tracked back to see where pedantic was added
to that function, and found it here:

Wed Feb 15 01:59:15 1989  Richard Stallman  (rms at sugar-bombs.ai.mit.edu)

        * c-typeck.c (decl_constant_value): Disable opt. if pedantic or
        outside functions, so that validity of program is never affected.

So it appears that the test for pedantic was added in the first place
purely to disable the optimization, perhaps because RMS perceived it
to be unsafe.


In the current compiler, it seems very likely that every call to
decl_constant_value_for_broken_optimization can simply be removed.
The constant propagation passes should implement the optimization.


I don't plan to work on this in the immediate future.

Ian

Reply via email to