[Patch, Fortran, 4.6] PR43178 - avoid unnecessary initialization/nullify

Tobias Burnus burnus@net-b.de
Mon Mar 29 18:15:00 GMT 2010


Hello all,

the patch was motivated to make -fdump-tree-original more readable, but
it should also have a tiny, tiny, tiny positive effect on the compile
time, run time and file size.

For instance, for a local, allocatable variable, one needs to set
var.data to zero. Well, that's what the current code does:

  struct t foo;
  foo.a.data = 0B;

    D.1557 = foo;
    if (D.1557.a.data != 0B)
        __builtin_free ((void *) D.1557.a.data);
    D.1557.a.data = 0B;

To summerize: First the variable is set to zero; then it is checked
whether it is allocated (which it isn't - if it were, it would be
freed), then it is set to zero again. With the patch the result is simply
  struct t foo;
  foo.a.data = 0B;

Similarly with local variables which have a default initializer, have no
SAVE, but are still in static memory (e.g. via -fmax-stack-var-size=n):

  static struct t2 x[10] = {{.a=5}, {.a=5}, {.a=5}, {.a=5}, {.a=5},
{.a=5}, {.a=5}, {.a=5}, {.a=5}, {.a=5}};
    t2.0.a = 5;
      while (1)
        {
          if (S.1 > 10) goto L.1;
          x[S.1 + -1] = D.1542;
          S.1 = S.1 + 1;
        }

If this is a local variable in a subroutine or function, there is no
need for the static initializer as it has to be reset every time the
procedure is called. However, for the main program, one can use the
static initializer as it is only called once.

The readability improvement really pays off of one has multidimensional
variables - but also the ".a=5" example with "x[1000]" instead of
"x[10]" has already a rather unfriendly dump.

Build and regtested on x86-64-linux.
OK for the 4.6 trunk?

Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: init-null5.diff
Type: text/x-patch
Size: 20263 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20100329/195479f6/attachment.bin>


More information about the Gcc-patches mailing list