From 9bc3d08d0b21e45f91536dca367b6d1bb2b762a5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 2 Mar 2021 19:45:08 -0800 Subject: 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. --- share/txr/stdlib/optimize.tl | 8 ++++++++ 1 file changed, 8 insertions(+) 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) -- cgit v1.2.3