On 04.06.20 07:52, Philipp Klaus Krause wrote:
We try to avoid peephole rules that do not reduce code size, as can be
very dangerous: With the large number of peephole rules it is hard to
thnk about a given rule will interact with all others, and with rule
that do not reduce code size it is very easy to end up with an endless
loop (i.e. SDCC would hang in the peephole optimizer).
This is pretty much the kind of answer I was looking forward to.
This was more meant as a general question than a proposal.
I'm still in the process of understanding how peep hole files should be
written.
Currently I would've used rearrenging rules to open new optimization
possibilities like:
replace {
and a, #0x%1%2
swap a
} by {
; swap and and swap
swap a
and a, #0x%2%1
} if notSame(%1 '0'), same(%2 '0')
replace {
swap a
and a, #0x%1%2
} by {
; swap and and swap
and a, #0x%2%1
swap a
} if notSame(%1 '0'), same(%2 '0')
since I found a way to optimize `and a, #0x0f;and a, #0x0N` but not `and
a, #0xf0;and a, #0xN0`.
Wouldn't it prevent the endless loop danger if the rule file starts with
repositioning rules followed by a barrier?
I guess the first transformations of things like this should rather move
into the assembly generator then:
replace {
xor a, a
} by {
; xor a to ld for better optmizations
ld a, #0x00
} if notUsed('f')
barrier
//because `ld a, #0x00` is a lot easier to handle than `xor a, a` if you
can do notUsed('f'):
replace {
ld %1, %5
push %1%2
inc sp
ld %3, %6
push %3%4
inc sp
} by {
; load via 16bit reg
ld c, %6
ld b, %5
push bc
} if notUsed('b'), notUsed('c'), canAssign(%1 'b'), canAssign(%3 'b'),
notUsed(%1), notUsed(%3), notSame(%5 'b' 'c' '(ld+)' '(ld-)'),
notSame(%6 'b' 'c' '(ld+)' '(ld-)')
replace {
ld a, #%1
push af
inc sp
ld a, #%2
push af
inc sp
} by {
ld a, #%1
push af
inc sp
; previous parameter
inc a
push af
inc sp
} if immdInRange(1 1 'sub' %2 %1 %3)
// and other rules that change `ld a, #0x01` into `inc a`
replace {
ld %2, #0x%3
ld %1, #0x%4
} by {
ld %1%2, #0x%3%4
; combined constant loads into register pair.
} if canAssign(%1%2 '#0x0102')
replace {
ld %1, #0x%3
ld %2, #0x%4
} by {
ld %1%2, #0x%3%4
; combined constant loads into register pair.
} if canAssign(%1%2 '#0x0102')
replace {
ld a, #0x00
} by {
; restore xor a
xor a, a
} if notUsed('f')
--
Freundliche Grüße / Yours sincerely
Sebastian Riedel
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user