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 ?
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.
Ticket moved from /p/sdcc/bugs/3074/
Can't be converted:
At least on gbz80 this needs
if notUsed('zf')for conversion, sincerlcadoes not set the zero flag.On z80 it would need
if notUsed('sf'), notUsed('zf'), notUsed('pf'), butnotUsedfor flags isn’t implemented there.The combination
con be converted with a rule though, since
andoverwrites all flags.I've tried to reproduce this using a small function, but failed:
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
Implemented in [r11703] in code generation, which is the right place, since it can potentially give more benefits there than in the peephole optimizer.