Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Yet another optimized bug
#1
Sample program test.bas:

Code:
GOTO 10

sub FASTCALL proc1()
    asm
start:
        ld hl,(stuff)
        ld (23672),hl
        ret
stuff:
        defw 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        defw 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        defw 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        defw 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    end asm
end sub

sub FASTCALL proc2(a AS UBYTE)
    asm
        cp      10
        jr      nz, skip
        dec     a
skip:
        jp      start
    end asm
end sub

10 proc1()
   proc2(0)

Compiling it using -O2 works correctly and produces the following code for routine proc2:

Code:
_proc2:
#line 17
        cp      10
        jr      nz, skip
        dec     a
skip:
        jp      start
#line 22
_proc2__leave:
        ret

Compiling it using -O3 produces error "Relative jump out of range" and produces the following code for routine proc2:

Code:
_proc2:
#line 17
        cp      10
        jr      nz, start
        dec     a
skip:
        jp      start
#line 22
_proc2__leave:
        ret

Again, the optimizer is supposed to try to optimize its own generated code only, not someone else's assembly code!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)