From 6988511ee608ec35c529ed2ee41ad2f324f4534b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 29 Nov 2021 07:18:00 -0800 Subject: compiler: new late-peephole case. This is related to the pattern in the previous commit. When we have a situation like this: lab1 mov tn nil lab2 ifq tn nil lab4 lab3 gcall tn ... We know that if lab1 is entered, then lab2 will necessarily fall through: the lab4 branch is not taken because tn is nil. But then, tn is clobbered immediately in lab3 by the gcall tn. In other words, the value stored into tn by lab1 is never used. Therefore, we can remove the "mov tn nil" instruction and move the l1 label. lab2 ifq tn nil lab4 lab1 lab3 gcall tn ... There are 74 hits for this pattern in stdlib. * stdlib/optimize.tl (basic-blocks late-peephole): Implement the above pattern. --- stdlib/optimize.tl | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'stdlib/optimize.tl') diff --git a/stdlib/optimize.tl b/stdlib/optimize.tl index a8e4ba9d..7a1a8bc0 100644 --- a/stdlib/optimize.tl +++ b/stdlib/optimize.tl @@ -609,6 +609,17 @@ ^(,(car insns) (jmp ,lab4) ,*(cddr insns))) + ((@(symbolp @lab1) + (mov (t @tn) (t 0)) + @lab2 + (ifq (t @tn) (t 0) @lab4) + @(symbolp @lab3) + (gcall (t @tn) . @grest) + . @rest) + ^(,lab2 + (ifq (t ,tn) (t 0) ,lab4) + ,lab1 + ,*(cddddr insns))) (((mov (t @tx) (t @ty)) (if (t @ty) @lab2) @(symbolp @lab1) -- cgit v1.2.3