optimization/3384: PowerPC -funroll-loops -fbranch-count-reg misoptimization
Zoltan Hidvegi
hzoli@austin.ibm.com
Mon Jun 25 12:25:00 GMT 2001
This may be related to PR 3384. The following little function
generates this code with gcc -O2 (note that -O2 turns on
-fbranch-count-reg):
void
do_loop(unsigned long c, char *m)
{
unsigned long i = 0;
do {
m[i] = 0;
} while (++i != c);
}
The assembly on powerpc-ibm-aix4.3.3.0 with gcc-3.0 -O2:
mr. 3,3
li 9,0
li 0,0
beq- 0,L..8
L..7:
mtctr 3
L..6:
stbx 0,4,9
addi 9,9,1
bdnz L..6
blr
L..8:
li 3,1
b L..7
So it checks if c==0, and in that case it only executes the loop once,
even though the loop should be executed 2^32 times, which is probably
not wat the caller wants, but still the program should just do what I
told in the source. The correct code would be
mtctr 3
li 9,0
li 0,0
L..6:
stbx 0,4,9
addi 9,9,1
bdnz L..6
blr
More information about the Gcc-bugs
mailing list