Menu

#686 Missing optimization rule ? (rlc a is used not rlca)

None
closed-fixed
None
5
2020-07-02
2020-07-01
Alan Cox
No

If you do return x < y then the compiler used ld a,0, rla, ld l,a, ret but if you do

return (x-y) & 0x8000

then it generates rlc a, and a, 1, ld l,a rather than using "rlca" which is a byte and 4 clocks shorter. I assume this should have a peephole rule ?

Discussion

  • Philipp Klaus Krause

     
  • Philipp Klaus Krause

    Can you provide a compileable example? What type do x and y have?

    I'd have to look at the code and what happens in code generation to see if this should be done in code generation vs. in the peephole optimizer.

    Anyway, the generated code is correct, so this is a feature request, not a bug regport.

     
  • Philipp Klaus Krause

    Ticket moved from /p/sdcc/bugs/3074/

    Can't be converted:

    • _category: Z80
     
  • Sebastian Riedel

    At least on gbz80 this needs if notUsed('zf') for conversion, since rlca does not set the zero flag.
    On z80 it would need if notUsed('sf'), notUsed('zf'), notUsed('pf'), but notUsed for flags isn’t implemented there.
    The combination

    rlc a
    and a, %1
    

    con be converted with a rule though, since and overwrites all flags.

     
  • Philipp Klaus Krause

    I've tried to reproduce this using a small function, but failed:

    int f(int x, int y)
    {
      return (x-y) & 0x8000;
    }
    

    I've tried return types unsigned int, int. I've tried types int, unsigned int, unsiged char, signed char for x and y.

    So far, I haven't been able to get rlc a. I compiled using sdcc -mz80

    P.S.: I see a few rlc a generated in some of the existing regression tests, and will have a look at those to see what could be done.

    P.P.S.: I can reproduce it now using f above: x and y of type unsigned int, return type _Bool.

     

    Last edit: Philipp Klaus Krause 2020-07-02
  • Philipp Klaus Krause

    • assigned_to: Philipp Klaus Krause
    • Group: -->
     
  • Philipp Klaus Krause

    • status: open --> closed-fixed
     
  • Philipp Klaus Krause

    Implemented in [r11703] in code generation, which is the right place, since it can potentially give more benefits there than in the peephole optimizer.

     

Log in to post a comment.