Menu

#3409 peep hole optimizer removes used labels

open
nobody
None
other
5
2022-06-03
2022-06-01
Under4Mhz
No

When I use the peephole optimizer, it removes labels that are being used if they're outside the scope of the function.

I'm using the same label in multiple places, so I've put in a separate function. Or I've put in one function, and call it from other places.

I could probably put this into it's own function, but it's not really a C function in that it's using a specific register.

Not sure if this is a bug or a misuse of asm, but it is an issue I'm having, so I thought I'd report it anyway.

void neg() {

    __asm

        jp l_neg_l                ; negate remainder

    __endasm;
}

void utils() __naked {

__asm    
l_neg_l:
        ld a,l
        cpl
        ld l,a
        inc l
        ret

    __endasm;
}

void main() { neg(); }
$ sdcc -mz80 ./peephole.c --peep-asm -o test

?ASlink-Warning-Undefined Global 'l_neg_l' referenced by module 'peephole'

$ sdcc -mz80 ./peephole.c -o test

$
sdcc -v
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/sm83/tlcs90/ez80_z80/z80n/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502 4.2.2 #13490 (Linux)
published under GNU General Public License (GPL)

Discussion

  • Maarten Brock

    Maarten Brock - 2022-06-03

    I suggest to move the contents of the naked function to a real asm file.
    Alternatively, rename utils to l_neg_l and use _l_neg_l for the jp.
    Or the final option: don't use --peep-asm.

     
  • Under4Mhz

    Under4Mhz - 2022-06-03

    No problem. Thanks.

    I tend to avoid --peep-asm now since I've had it introduce issues into the executable in the past.

     

Log in to post a comment.

Auth0 Logo