summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-03-02 19:45:08 -0800
committerKaz Kylheku <kaz@kylheku.com>2021-03-02 19:45:08 -0800
commitf70532d9f2e2b51e4d9f878573682672efaf993f (patch)
treee54bf6b97a6c48e4a906384cf855c2edc7101508
parent5bdef4456bf7abce17304414077f14fed528fb54 (diff)
downloadtxr-f70532d9f2e2b51e4d9f878573682672efaf993f.tar.gz
txr-f70532d9f2e2b51e4d9f878573682672efaf993f.tar.bz2
txr-f70532d9f2e2b51e4d9f878573682672efaf993f.zip
compiler: move short end sequences before branch.
When a function ends like this: jmp label ... label: end t42 The jmp can just be replaced by "end t42". * share/txr/stdlib/optimize.tl (basic-blocks peephole-block): Implement the pattern to replace a jump to a one or two instruction sequence ending in a jend with that sequence. Including the extra instruction helps if the target has not been peepholed yet. In the pattern matching Ackermann case, two instructions are promoted, one of which is eliminated.
-rw-r--r--share/txr/stdlib/optimize.tl8
1 files changed, 8 insertions, 0 deletions
diff --git a/share/txr/stdlib/optimize.tl b/share/txr/stdlib/optimize.tl
index 411af8d9..73aa6dc6 100644
--- a/share/txr/stdlib/optimize.tl
+++ b/share/txr/stdlib/optimize.tl
@@ -391,6 +391,14 @@
(@(require ((ifq @(as reg (d @dn)) (t 0) @jlabel) . @nil)
(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))))
(@else insns)))
(defmeth basic-blocks peephole (bb)