This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/50910] New: [avr] inefficient division by 2
- 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: Sat, 29 Oct 2011 12:16:07 +0000
- Subject: [Bug target/50910] New: [avr] inefficient division by 2
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50910
Bug #: 50910
Summary: [avr] inefficient division by 2
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: target
AssignedTo: gjl@gcc.gnu.org
ReportedBy: gjl@gcc.gnu.org
CC: eric.weddington@atmel.com
Target: avr
The following source
char c;
void bar_c (int x)
{
c = x ? x/2 : c+1;
}
reveals two issues
== 1 ==
Compiled with
$ avr-gcc -S -Os
there is a call to libgcc's division routine. RTX costs of division has to be
checked and costs of loading the constant added to the costs of division.
bar_c:
sbiw r24,0
breq .L2
ldi r22,lo8(2)
clr r23
rcall __divmodhi4
rjmp .L3
.L2:
lds r22,c
subi r22,lo8(-(1))
.L3:
sts c,r22
ret
== 1 ==
Compiled with
$ avr-gcc -S -O2
the code is happily jumping around to L7 and then back to L3.
bar_c:
sbiw r24,0
brne .L6
lds r24,c
subi r24,lo8(-(1))
sts c,r24
ret
.L6:
sbrc r25,7
rjmp .L7
.L3:
asr r25
ror r24
sts c,r24
ret
.L7:
adiw r24,1
rjmp .L3
Presumably, the cause is
#define BRANCH_COST 0
in avr.h, and the sequence could be instead:
...
.L6:
sbrc r25,7
adiw r24,1
.L3:
asr r25
ror r24
sts c,r24
ret