This is the mail archive of the gcc@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: An unusual Performance approach using Synthetic registers


> > 2) Running the RA over the stack slots will cause the slots to be reused
> > when the life range of variables does not overlap. This even increases
the
> > compactness that already gives the benefit of point 1. Also, overall
> > reducing stack usage will always be a small gain.
>
> The stack slots are already reused.

Stack slots are not reused. Neither stack slots allocated for local
variables, nor stack slots created for temporaries. See the following
example:

void dummy(int, int);

void test(void)
{
  int a1,b1,c1,d1;
  int a2,b2,c2,d2;

  c1=d1=0;
  for (a1=0; a1<10; a1++)
    for (b1=0; b1<=a1; b1++) {
      c1+=a1*a1;
      d1+=b1;
      dummy(c1,d1);
     }
  c2=d2=0;
  for (a2=0; a2<10; a2++)
    for (b2=0; b2<=a2; b2++) {
      c2+=a2*a2;
      d2+=b2;
      dummy(c2,d2);
     }
}


Compiling with -O3 -march=pentium4 , this gives:

_test:
 pushl %ebp
 movl %esp, %ebp
 pushl %edi
 xorl %edi, %edi
 pushl %esi
 xorl %esi, %esi
 pushl %ebx
 subl $28, %esp
 movl $0, -16(%ebp)
L11:
 xorl %ebx, %ebx
 cmpl %esi, %ebx
 jg L25
 movl %esi, %edx
 imull %esi, %edx
 movl %edx, -24(%ebp)
L10:
 addl %ebx, -16(%ebp)
 addl -24(%ebp), %edi
 addl $1, %ebx
 movl -16(%ebp), %eax
 movl %edi, (%esp)
 movl %eax, 4(%esp)
 call _dummy
 cmpl %esi, %ebx
 jle L10
L25:
 addl $1, %esi
 cmpl $9, %esi
 jle L11
 movl $0, -20(%ebp)
 xorl %edi, %edi
 xorl %esi, %esi
L21:
 xorl %ebx, %ebx
 cmpl %esi, %ebx
 jg L29
 movl %esi, %edx
 imull %esi, %edx
 movl %edx, -28(%ebp)
L20:
 addl %ebx, -20(%ebp)
 addl -28(%ebp), %edi
 addl $1, %ebx
 movl -20(%ebp), %eax
 movl %edi, (%esp)
 movl %eax, 4(%esp)
 call _dummy
 cmpl %esi, %ebx
 jle L20
L29:
 addl $1, %esi
 cmpl $9, %esi
 jle L21
 addl $28, %esp
 popl %ebx
 popl %esi
 popl %edi
 popl %ebp
 ret

Stack slots are created for a1 (ebp-16) abd s2 (ebp-20), even though thos 2
variables do not overlap and could share a same stack slot. The same holds
for the expression a1*a1 which is stored in ebp-24 and a2*a2 which is stored
in ebp-28. A single stack slot could be used for both expressions as there
is no overlap in the life range.

Marcel




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]