optimization/9540: C99 initializers generate lots of code

Christian Ehrhardt ehrhardt@mathematik.uni-ulm.de
Tue May 13 13:41:00 GMT 2003


http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9540

The code size of the two functions differs because you do two
fundamentally different things:

* new_vector1 creates a compound literal (this is a separate object not
  just an initializer!) of type string. The contents of this object
  are then assigned to *result.
* new_vector2 initializes *result directly without the construction of
  an intermediate compound literal.

The additional instructions that you see are the result of the copying
which is in general necessary because we can't know if gc_malloc might
rely on the memory in *result or might modify previously initialized
elements of the compound literal. The latter might be impossible
due to aliasing rules but I'm not entirly sure about this. The former
is definitely possible, e.g. if the first call to gc_malloc also stored
the return value in some static or global variable.

Given the fact that gcc does optimize the mem to mem copy away if
the compound literal is declared const and gc_malloc is called outside
of the initializer I guess that there aren't enough aliasing restrictions
to allow the optimization otherwise.

   regards  Christian

-- 
THAT'S ALL FOLKS!



More information about the Gcc-bugs mailing list