Register Allocation
John Lu
jlu@lsil.com
Fri Mar 26 22:21:00 GMT 2004
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
More information about the Gcc
mailing list