From 9e5159e4457b6ae427471cdafa954652806c5f60 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 17 Mar 2021 06:54:19 -0700 Subject: compiler: improve end-propagating optimization. When a jmp instruction is replaced by the end instruction that it jumps to, or possibly by a two-instruction sequence ending in end, there can be more opportunities to optimize. For instance, the second reduction in a sequence like this: mov t3, t5 mov t3, t5 jmp label --> end t3 --> end t5 ... label: end t3 * share/txr/stdlib/optimize.tl (basic-blocks peephole-block): If the end-propagation is done, we change the linkage of the current block to indicate that it has no next blocks. We add it to the rescan list and set the recalc flag so the liveness information is updated. --- share/txr/stdlib/optimize.tl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/share/txr/stdlib/optimize.tl b/share/txr/stdlib/optimize.tl index cf8a42b0..31702cb4 100644 --- a/share/txr/stdlib/optimize.tl +++ b/share/txr/stdlib/optimize.tl @@ -425,13 +425,19 @@ (not (memqual reg bb.lt-dregs))) ^((jmp ,jlabel))) (((jmp @jlabel) . @rest) - (let ((jinsns (cdr [bb.hash jlabel].insns))) - (match-case jinsns - (((jend @nil) . @nil) - ^(,(car jinsns) ,*rest)) - ((@nil (jend @nil) . @nil) - ^(,(car jinsns) ,(cadr jinsns) ,*rest)) - (@else insns)))) + (let* ((jinsns (cdr [bb.hash jlabel].insns)) + (oinsns (match-case jinsns + (((jend @nil) . @nil) + ^(,(car jinsns) ,*rest)) + ((@nil (jend @nil) . @nil) + ^(,(car jinsns) ,(cadr jinsns) ,*rest)) + (@else insns)))) + (when (neq insns oinsns) + (pushnew bl bb.rescan) + (set bb.recalc t + bl.next nil + bl.links nil)) + oinsns)) (@else insns)))) (defmeth basic-blocks peephole (bb) -- cgit v1.2.3