Menu

#1756 Overly aggressive Z80 peephole optimizer

closed-works-for-me
z80 port (189)
5
2011-02-18
2011-02-12
Anonymous
No

Compiled with: -mz80 --data-loc 0xC001
SDCC 3.0.0 #6037 (MINGW32)

See the attchment for C code.

This is what happens in move_to_next:

;sdcc_bug.c:22: ((games.firstShown + 9) < games.count) )
ld bc, #0x0009
add hl,bc
ld a, l
ld b, h
sub a,e
ld a,b
sbc a,d
ret NC
;sdcc_bug.c:23: games.firstShown++;
inc hl <-- HL is never reloaded, so it will become firstShown+10 here, not firstShown+1 like it should be
ld c,l
ld b,h
ld hl,#_games
ld (hl),c
inc hl
ld (hl),b

And in asic_cmd:

;sdcc_bug.c:33: *(volatile BYTE*)0xBFC0 = cmd;
ld hl,#0xBFC0
ld a,4 (ix)
ld (hl),a
;sdcc_bug.c:34: *(volatile BYTE*)0xFFFE = data >> 13;
ld a,6 (ix)
rlca
rlca
rlca
and a,#0x07
ld (hl), a <-- A should be written to 0xFFFE, but instead it's written to 0xBFC0

Discussion

  • Philipp Klaus Krause

    I just tested in current revision #6223, and I cannot reproduce this bug (neither in trunk, nor in the optralloc branch). I have fixed some bugs in the handling of hl in the register allocator recently, and most likely this was one of them.

    Philipp

     
  • Philipp Klaus Krause

    • labels: 841812 --> z80 port
    • assigned_to: nobody --> spth
    • status: open --> closed-works-for-me
     

Log in to post a comment.