From beac7fcc9cf4c7533d658e7c4839b715d6c714cd Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 26 Nov 2021 20:11:58 -0800 Subject: compiler: replace late-peephole pattern with real approach. * stdlib/optimize.tl (basic-blocks merge-jump-thunks): For each group of candidate jump-blocks, search the entire basic block list for one more jump block which is identical to the others, except that it doesn't end in a jmp, but rather falls through to the same target that the group jumps to. That block is then included in the group, and also becomes the default leader since it is pushed to the front. (basic-blocks late-peephole): Remove the peephole pattern which tried to attack the same problem. The new approach is much more effective: when compiling stdlib, 77 instances occur in which such a block is identified and added! The peephole pattern only matched six times. --- stdlib/optimize.tl | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'stdlib/optimize.tl') diff --git a/stdlib/optimize.tl b/stdlib/optimize.tl index 57eca186..2274e424 100644 --- a/stdlib/optimize.tl +++ b/stdlib/optimize.tl @@ -564,6 +564,14 @@ bb.list)) (hash (group-by [chain .insns cdr] candidates))) (dohash (insns bls hash) + (let ((link (car (car bls).links))) + (each ((bb bb.list)) + (if (and (not (member bb bls)) + (null (cdr bb.links)) + (eq bb.next link) + (starts-with (cdr bb.insns) insns) + (eql (len bb.insns) (len insns))) + (push bb bls)))) (when (cdr bls) (whenlet ((keep (or (keep-if (op some @1.rlinks (op eq @@1) .next) bls) (list (car bls)))) @@ -625,18 +633,6 @@ ,lab2 (end (t ,ty)) ,*rest)) - ((@(symbolp @lab1) - @(consp @insn) - (jmp @lab3) - @(symbolp @lab2) - @insn - @(symbolp @lab3) - . @rest) - ^(,lab1 - ,lab2 - ,insn - ,lab3 - ,*rest)) (@else else))) (defun rewrite (fun list) -- cgit v1.2.3