Re: [cc65] Optimization possible?

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2009-10-24 19:07:05
Hi!

On Sat, Oct 24, 2009 at 12:32:47PM +0000, Thomas Giesel wrote:
> Is it possible to repeat the peephole optimization until no more changes happened?

This is already done, but it won't solve the order problem. In the given case,
there were (simplified) four replacements involved:

  1. One that generates code like

                adc     xxx
                bcc     L
                inx
        L:

     from more complex calls like tosaddax.

  2. One that checks for

                adc     xxx
                bcc     L
                inx
        L:

     (which is also generated by the compiler in some places) and removes
     it, if X isn't used later.

  3. Another one that check for a bcc to clc or bcs to sec and changes
     the branch to skip the instruction.

  4. A fourth one that removes register operations for a register that isn't
     used later.

Groepaz code had two additions, so after step one, the code looked like this:

                adc     xxx
                bcc     L
                inx
        L:      clc
                adc     #$01
                ldy     #$xx
                sta     (sp),y

Now step 3. was run and changed the code like this:

                adc     xxx
                bcc     L
                inx
                clc
        L:      adc     #$01
                ldy     #$xx
                sta     (sp),y

If you now run step 2. it won't find what it searches for. Step 4. will
finally remove the "inx", since X isn't used later, and you end with:

                adc     xxx
                bcc     L
                clc
        L:      adc     #$01
                ldy     #$xx
                sta     (sp),y

As can be easily seen, repeating these steps won't generate a different
result, you have to change the order of the steps. In the given case, it is
clear that the choosen order was wrong for any case I can currently think of.
But this is not always the true. There may be code combinations for which one
order may be better, while reversing the order is better for another.

> Maybe this could even reduce the number of rules and make the design about the
> right order simple. Possibly I'm too naive...

In this special case: yes. :-)

Regards


        Uz

  

P.S.: Please don't write to my personal mailing address and cc: to the list
      (or the other way round). I promise, I'm reading the list, so writing to
      both addresses will just cause confusion.

-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sat Oct 24 19:14:42 2009

This archive was generated by hypermail 2.1.8 : 2009-10-24 19:14:44 CEST