|
Phase #4:
Reorder branches
|
Reverse the conditional branches immediately followed by an absolute
branch, and eliminate that absolute branch.
This step will reduce the code size and control flow complexity.
Eliminate labels that are unused after the above reordering, and
reduce branch logic where possible.
Separate argument list generation from
other operations.
|
.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
|
reverse conditional branch and purge absolute branch
|
nop
ba .l7
nop
|
1:
|
purge unused label
|
.l2:
srl %o0,1,%g2
btst 1,%o0
bne .l3
nop
inc %i2
srl %o0,1,%o0
ba .l4
nop
.l3:
add %o0,%g2,%g2
inc 2,%i2
add %g2,1,%o2
cmp %o2,%o0
bcs .l6
nop
mov %o2,%o0
.l4:
cmp %o0,1
be 1f
nop
ba .l2
nop
1:
ba .l8
nop
|
.l6:
mov %o2,%o0
restore %g0,0,%o0
retl
nop
|
move this segment down, so we can eliminate another absolute branch;
remove the mov that has no effect
|
.l7:
.l8:
cmp %i2,%o1
bgu 1f
nop
inc %i1
ba .l9
nop
1:
mov %i0,%o0
mov %i1,%o1
|
inc %i1
|
separate opcode from argument list
preparation
|
mov %i2,%o2
call printf
nop
mov %i2,%o1
.l9:
mov %i1,%o0
clr %i2
ba .l1
nop
.type main,2
.size main,(.-main)
|
|