------- Comment #2 from carrot at google dot com 2009-06-23 09:09 -------
Created an attachment (id=18053)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18053&action=view)
test case
Compile the attached code with options -mthumb -march=armv5te -Os, gcc
generates
push {lr}
cmp r1, #1
bne .L3
mov r3, #2
b .L2
.L3:
mov r3, #0
.L2:
add r0, r3, r0
pop {pc}
A better code sequence can be:
push {lr}
mov r3, 0
cmp r1, #1
bne .L3
mov r3, #2
.L3:
add r0, r3, r0
pop {pc}
With this optimization, we can reduce 1 instruction. For both equal and not
equal case, the number of executed instructions is same as previous. But in
equal case one branch instruction is replaced by a move instruction. So it is
also win for performance.
Which pass should this optimization be done? Jump pass or bb reorder pass?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40525