|
Phase #3:
More code reordering:
conditional codes |
The next step reorders code, to move opcodes, that set conditional
codes, to their associated conditional branches.
This may eliminate some code repetitions introduced by
optimizers.
When moving opcodes to a place after a conditional branch, they need
only be duplicated if both instances have an effect (i.e. destination
registers are not immediately overwritten).
|
.section ".rodata1",#alloc
.align 4
.l0:
.asciz "%u %u\n"
.section ".text",#alloc,#execinstr
.align 4
.global main
main:
save %sp,-96,%sp
set .l0,%i0
mov 1,%i1
clr %o1
mov 1,%o0
clr %i2
.l1:
cmp %i1,1
bne 1f
nop
|
btst 1,%o0
|
remove opcode that has
no effect
|
ba .l7
nop
1:
|
btst 1,%o0
|
move test to its associated conditional branch
|
.l2:
srl %o0,1,%g2
bne .l3
nop
inc %i2
srl %o0,1,%o0
cmp %o0,1
ba .l4
nop
.l3:
add %o0,%g2,%g2
inc 2,%i2
add %g2,1,%o2
cmp %o2,%o0
|
mov %o2,%o0
|
in this case the mov is moved
|
bcs .l6
nop
|
cmp %o0,1
|
place it after the label
|
.l4:
be 1f
nop
btst 1,%o0
ba .l2
nop
1:
|
btst 1,%o0
|
this opcode can be instantly eliminated
|
cmp %i2,%o1
ba .l8
nop
.l6:
restore %g0,0,%o0
retl
nop
.l7:
cmp %i2,%o1
.l8:
bgu 1f
nop
inc %i1
ba .l9
nop
1:
mov %i0,%o0
mov %i1,%o1
inc %i1
mov %i2,%o2
call printf
nop
mov %i2,%o1
.l9:
mov %i1,%o0
clr %i2
ba .l1
nop
.type main,2
.size main,(.-main)
|
|