This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/33970] Missed optimization using unsigned char loop variable
- From: "gjl at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 20 Jul 2011 17:48:02 +0000
- Subject: [Bug middle-end/33970] Missed optimization using unsigned char loop variable
- Auto-submitted: auto-generated
- References: <bug-33970-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33970
Georg-Johann Lay <gjl at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |gjl at gcc dot gnu.org
Resolution| |WORKSFORME
Target Milestone|--- |4.7.0
Known to fail| |
--- Comment #13 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2011-07-20 17:47:44 UTC ---
Cloased as WORKS FOR ME.
Using the following test case:
volatile unsigned char bar;
void foo(void)
{
unsigned char x;
for(x=0;x<128; x++)
{
bar = x;
}
}
int sub2 (unsigned char);
void foo2 (void)
{
unsigned char x;
for(x=0;x<128; x++)
{
sub2 (x);
}
}
void foo21 (void)
{
unsigned char x;
for(x=0;x<128; x++)
{
sub2 (x+1);
}
}
And with avr-gcc 4.7 r176517 I get the following result (-Os -mmcu=atmega8).
In no case there is a 16-bit loop variable used.
foo:
ldi r24,lo8(0)
.L5:
sts bar,r24
subi r24,lo8(-(1))
cpi r24,lo8(-128)
brne .L5
ret
foo2:
push r28
ldi r28,lo8(0)
.L8:
mov r24,r28
rcall sub2
subi r28,lo8(-(1))
cpi r28,lo8(-128)
brne .L8
pop r28
ret
foo21:
push r28
ldi r28,lo8(0)
.L11:
subi r28,lo8(-(1))
mov r24,r28
rcall sub2
cpi r28,lo8(-128)
brne .L11
pop r28
ret
.ident "GCC: (GNU) 4.7.0 20110720 (experimental)"