This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Register Allocation
- From: John Lu <jlu at lsil dot com>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 26 Mar 2004 13:54:41 -0600 (CST)
- Subject: Register Allocation
- Reply-to: John Lu <jlu at lsil dot com>
Hi,
I've been working on a port based on gcc-3.3 and I've noticed that
better assembly code is generated if the C source has
separate variables declared for distinct live ranges.
For example,
int foo1(int *p1, int *p2) {
int i; /* one index variable for two live ranges */
int total;
total=0;
for (i=0; i<100; i++) {
total+=p1[i];
}
for (i=0; i<100; i+=2) {
total+=p1[i];
}
return(total);
}
produces worse code than:
int foo2(int *p1, int *p2) {
int i1,i2; /* two index variables for two live ranges */
int total;
total=0;
for (i1=0; i1<100; i1++) {
total+=p1[i1];
}
for (i2=0; i2<100; i2+=2) {
total+=p1[i2];
}
return(total);
}
In my port, i1 is allocated a loop register which supports faster looping,
and i2 is allocated to a gpr because a decrement by two is needed. When
only one index variable is declared, "i" is allocated to a loop register,
but this creates bad code for the second loop, since decrement by two is
not supported for loop registers. This happens with and without the
"-fnew-ra" option.
I was wondering if anyone else has seen this or am I doing something wrong
in my port.
Thanks,
John Lu