From 21bd7298ac8110322db108f2c8be78adbb43b6b1 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 28 Sep 2021 06:54:37 -0700 Subject: compiler: code clean-up in peephole optimizer. * stdlib/optimize.tl (basic-blocks peephole-block): When we match a branching instruction, including jend, we know that's the end of the basic block. So there is no need to splice the (rest insns) into the output; let's get rid of that. On the other hand, there is also no need to have a specific pattern match for the end of the list such as ((jmp @label)). This costs extra cycles to validate. Let's consistently match these basic-block terminating instructions using prefix patterns like ((jmp @label) . @nil)). --- stdlib/optimize.tl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/optimize.tl b/stdlib/optimize.tl index 8d2c1f5c..f6acad64 100644 --- a/stdlib/optimize.tl +++ b/stdlib/optimize.tl @@ -378,7 +378,7 @@ (pushnew bl bb.rescan) (set bb.recalc t bb.reelim t) - ^((jmp ,jlabel) ,*(cdr insns))) + ^((jmp ,jlabel))) (@(require ((@(or gcall gapply) (t @n) @idx . @nil) . @nil) (dead-treg (car insns) n) [%effect-free% [bb.symvec idx]]) @@ -414,7 +414,7 @@ . @rest) ^(,(cadr insns) ,(car insns) ,*rest)) (((@(or frame dframe) . @nil) - (if (t @reg) @jlabel)) + (if (t @reg) @jlabel) . @nil) (let ((jinsns [bb.hash jlabel].insns)) (match-case jinsns ((@jlabel @@ -437,13 +437,13 @@ (@(require ((ifq @(as reg (d @dn)) (t 0) @jlabel) . @nil) (not (memqual reg bb.lt-dregs))) ^((jmp ,jlabel))) - (((jmp @jlabel) . @rest) + (((jmp @jlabel) . @nil) (let* ((jinsns (cdr [bb.hash jlabel].insns)) (oinsns (match-case jinsns (((jend @nil) . @nil) - ^(,(car jinsns) ,*rest)) + ^(,(car jinsns))) ((@nil (jend @nil) . @nil) - ^(,(car jinsns) ,(cadr jinsns) ,*rest)) + ^(,(car jinsns) ,(cadr jinsns))) (@else insns)))) (when (neq insns oinsns) (pushnew bl bb.rescan) -- cgit v1.2.3