diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-03-02 19:45:08 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-03-02 19:45:08 -0800 |
commit | 9bc3d08d0b21e45f91536dca367b6d1bb2b762a5 (patch) | |
tree | e54bf6b97a6c48e4a906384cf855c2edc7101508 | |
parent | ed4ddd978ac564b83d09cfe96f97c993442cc195 (diff) | |
download | txr-9bc3d08d0b21e45f91536dca367b6d1bb2b762a5.tar.gz txr-9bc3d08d0b21e45f91536dca367b6d1bb2b762a5.tar.bz2 txr-9bc3d08d0b21e45f91536dca367b6d1bb2b762a5.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.tl | 8 |
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) |