#72 Z80 peephole improvement


I have looked at the assembler code generated by sdcc
from my C code. I noticed some frequent innefficient
code sections.
I created peephole rules for these. Some peephole rules
required a change in code generation, which I
implemented. This change made an old peephole rule
obsolete; I removed that one.

I have recompiled the library, run the regression tests
and verified that my own Z80 programs work.



  • Philipp Klaus Krause

    Logged In: YES

    This is an updated version of the patch with a new peephole
    rule added.

    Description of the patch:
    I implemented label reference counting (I looked at the
    mcs51 peepholes to see how it's done), removal of
    unreferenced labels (which allows further optimization by

    sdcc often generates code where two values are compared for
    equality and later something is set to zero.
    my patch makes code genration emit sub instructions instead
    of cp. if the values tested are equal the register a is zero
    after the sub instruction. The peephole rules exlpoit this
    to use this zero. Example:

    sdcc generates

    sub a, b
    jp nz, somewhere
    ld a, #0x00

    my peephole rule changes this to

    sub a, b
    jp nz, somewhere
    ld a, a

    since the ld a, a is horter and faster than ld a, #0x00 the
    restart lets another peephole rule optimize the ld a, a
    away. Another similar case would be

    or a, a
    jp nz, somewhere
    ld a, b
    or a, a

    which my peephole rules optimize into
    or a, a
    jp nz, somewhere
    or a, b

    using the knowledge that a is zero.

    There's another peephole that redirects jumps and one that
    replaces conditional long jumps by conditional short jumps
    if possible. The conditinal short jump needs one byte less
    than the long one (and is faster if the condition is false).


  • Maarten Brock

    Maarten Brock - 2006-11-03

    Logged In: YES

    Applied in SDCC 2.6.1 #4459.

  • Maarten Brock

    Maarten Brock - 2006-11-03
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-accepted

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks