[tree-ssa] -fgcse and friends useless

Richard Guenther rguenth@tat.physik.uni-tuebingen.de
Fri Feb 6 12:25:00 GMT 2004


Hi!

It seems that the tree-optimizers do all the work that rtl level gcse and
friends (gcse-lm, gcse-sm, gcse-las) do.  I.e. disabling these gcse
optimizers while doing -O2 -funroll-loops -ffast-math -march=athlon
-fno-exceptions -ftree-points-to=andersen -ftree-sra -fomit-frame-pointer
leaves me with exactly the same performance of the resulting code.

So this is good news(?).

But still the most weak point of gcc is its loop optimizer which produces
inner loops with lots of useless statements like:

.L6311:
        movl    32(%esp), %eax  #, T.32763
        movl    %esi, 64(%esp)  # i0,
        movl    %edi, %ebx      # i1, tmp160
        movl    %edi, 68(%esp)  # i1,
        movl    %ebp, 72(%esp)  # i2,
        movl    %esi, 48(%esp)  # i0,
        movl    %edi, 52(%esp)  # i1,
        movl    44(%eax), %edx  # <variable>.ptr_m, <variable>.ptr_m
        movl    %ebp, 56(%esp)  # i2,
        movl    40(%eax), %eax  # <variable>.offset_m, <variable>.offset_m
        movl    8(%edx), %edx   # <variable>.pBegin_m, <variable>.pBegin_m
        leal    (%eax,%eax,8), %eax     #, tmp153
        leal    (%edx,%eax,8), %eax     #, <anonymous>
        movl    %esi, %edx      # i0, offset
        imull   28(%eax), %ebx  # <variable>.strides_m, tmp160
        imull   24(%eax), %edx  # <variable>.strides_m, offset
        movl    64(%eax), %ecx  # <variable>.data_m, T.34744
        addl    %ebx, %edx      # tmp160, offset
        movl    %ebp, %ebx      # i2, tmp160
        imull   32(%eax), %ebx  # <variable>.strides_m, tmp160
        addl    %ebx, %edx      # tmp160, offset
        fldz
        fstpl   (%ecx,%edx,8)   #* T.34744
        incl    %esi    # i0
.L6320:
        cmpl    20(%esp), %esi  # <anonymous>, i0
        jle     .L6311  #,

look at all the stack slots that get assigned the same variables
(i0,i1,i2) and aren't
even used inside the loop, but just stored to.  The above is result of
leafified C++ math kernel with a triple nested loop, roughly equivalent to

void foo(double *a, int o, int f0, int e0, int f1, int e1,
	int f2, int e2, int s0, int s1, int s2)
{
  for (int i2=f2; i2<=e2; ++i2)
    for (int i1=f1; i1<=e1; ++i1)
      for (int i0=f0; i0<=e0; ++i0)
        a[o + i0*s0 + i1*s1 + i2*s2] = 0.0;
}

optimizing the above c-loop doesn't produce the useless stack slots, but
can't optimize the address calculation of the innermost loop, too.
Something like the following would be expected to happen:

void foo2(double *a, int o, int f0, int e0, int f1, int e1,
	int f2, int e2, int s0, int s1, int s2)
{
  for (int i2=f2; i2<=e2; ++i2)
    for (int i1=f1; i1<=e1; ++i1) {
      double *a2 = &a[o + f0*s0 + i1*s1 + s2*s2];
      for (int i0=f0; i0<=e0; ++i0) {
        *a2 = 0.0;
        a2 += s0;
      }
    }
}

Richard.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/



More information about the Gcc mailing list