[Bug other/60486] [avr] missed optimization on detecting zero flag set
gjl at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Mar 10 17:07:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60486
Georg-Johann Lay <gjl at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |gjl at gcc dot gnu.org
--- Comment #1 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
Created attachment 32326
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32326&action=edit
C test case
Here is a valid test case.
Compiled with avr-gcc 4.8.2
$ avr-gcc pr60486.c -S -Os -mmcu=atmega8 -dp
we get:
pr60486:
movw r18,r24 ; 5 *movhi/1 [length = 1]
.L2:
cp r22,r24 ; 21 *cmphi/3 [length = 2]
cpc r23,r25
brsh .L7 ; 22 branch [length = 1]
subi r18,1 ; 13 addhi3_clobber/2 [length = 2]
sbc r19,__zero_reg__
cp r18,__zero_reg__ ; 14 *cmphi/2 [length = 2]
cpc r19,__zero_reg__
breq .L5 ; 15 branch [length = 1]
adiw r24,1 ; 17 addhi3_clobber/1 [length = 1]
rjmp .L2 ; 55 jump [length = 1]
.L7:
ldi r24,0 ; 7 *movhi/2 [length = 2]
ldi r25,0
ret ; 49 return [length = 1]
.L5:
ldi r24,lo8(1) ; 6 *movhi/5 [length = 2]
ldi r25,0
ret ; 51 return [length = 1]
The superfluous insn is #14 (*cmphi).
This worked with 4.7 with the output as follows:
pr60486:
movw r18,r24 ; 7 *movhi/1 [length = 1]
rjmp .L2 ; 48 jump [length = 1]
.L4:
subi r18,1 ; 15 addhi3_clobber/2 [length = 2]
sbc r19,__zero_reg__
breq .L5 ; 17 branch [length = 1]
adiw r24,1 ; 19 addhi3_clobber/1 [length = 1]
.L2:
cp r22,r24 ; 23 *cmphi/3 [length = 2]
cpc r23,r25
brlo .L4 ; 24 branch [length = 1]
ldi r18,0 ; 9 *movhi/2 [length = 2]
ldi r19,0
rjmp .L3 ; 50 jump [length = 1]
.L5:
ldi r18,lo8(1) ; 8 *movhi/5 [length = 2]
ldi r19,0
.L3:
movw r24,r18 ; 56 *movhi/1 [length = 1]
ret ; 55 return [length = 1]
More information about the Gcc-bugs
mailing list