Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## #252 Matching stuff like -4(ix) in the peephole optimizer

closed
None
5
2008-07-12
2008-03-19
No

Currently a line like
ld a,-4(ix)
can be matched by
a rule like
ld %1,-4(%2)
however I would like to be able to match it with
ld %1,%2(%3)

In the Z80 port I see lots of lines like the example and can't optimize them in the peephole optimizer since I can't match them (except by lots of rules with the numbers written explicitly).

Philipp

P.S.: Typical example I've seen often:
ld b,h
ld c,l
ld -4(ix),c
ld -3(ix),b
could be optimized into
ld -4(ix),l
ld -3(ix),h
if the value in bc is never read, but currently I can't match the ld -4(ix),c and ld -3(ix,b).

Philipp

## Discussion

• Maarten Brock
2008-03-19

Logged In: YES
user_id=888171
Originator: NO

Do you have any idea why this notation is used in the first place? It is not following the Zilog Z80 user manual mnemonic notation. Doesn't the assembler accept that notation? If it would be followed, this would be much easier.
E.g.

ld (ix-4),c

would match

ld (%1-%2),%3

The current implementation of bindVar matches the whole '-4(ix)' to %2 and then matchLine can't match anything to '(%3)'. An alternative would be to generate an extra space (e.g. '-4 (ix)'), but I don't know if the assembler likes that either. And it will probably give problems with other peephole rules.

Maarten

• Maarten Brock
2008-03-19

Logged In: YES
user_id=888171
Originator: NO

Another thought: reversing the order would also give a match.

ld (ix)-4,c

would match

ld (%1)%2,%3

• Maarten Brock
2008-03-19

Logged In: YES
user_id=888171
Originator: NO

And finally, if there is no need to identify these two parts you can already use:

ld %1,%2

to match

ld -4(ix),c

• assigned_to: nobody --> spth

• Logged In: YES
user_id=564030
Originator: YES

I have no idea why sdcc uses this notation.
I'll probably change it to -4 (ix) since it seems to be the smallest change and is thus the least likely to break anything. I sometimes need the number separately from the rest and it's a cheap way of distinguishing the likes of -4 (ix) from other operands like registers, register pairs, etc, which is useful, too.

Philipp

• status: open --> closed

• Logged In: YES
user_id=564030
Originator: YES

Implemented in revision #5198.