From cdeb5bfa8b2fae5cfd8d427d347fbe9195e2d115 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 2 Mar 2021 07:11:48 -0800 Subject: compiler: reorder optimization passes. * share/txr/stdlib/compiler.tl (compiler optimize): Perform the control flow optimizations of jump threading and dead code elimination first. Then, do the data-flow-assisted optimizations on the re-calculated control flow graph. With this, two more useless insructions are shaved off the pattern matching Ackermann: (defun ack (:match) ((0 @n) (+ n 1)) ((@m 0) (ack (- m 1) 1)) ((@m @n) (ack (- m 1) (ack m (- n 1))))) It now compiles down to 16 instructions instead of 18; and the speedup of (ack 3 7) versus interpreted goes from 36.0 to 37.3 times. The reason that the new reduction in the code is possible is that previously, the code being analyzed was in separate basic blocks, which are now merged together in the dead code elimination pass. * share/txr/stdlib/compiler.tl (compiler optimize): Move calc-liveness and peephole after elim-dead-code. --- share/txr/stdlib/compiler.tl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index 59050ff5..6b1c1a17 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -1504,10 +1504,10 @@ (defmeth compiler optimize (me insns) (let* ((lt-dregs (mapcar .oreg me.lt-frags)) (bb (new (basic-blocks insns lt-dregs)))) - bb.(calc-liveness) - bb.(peephole) bb.(thread-jumps) bb.(elim-dead-code) + bb.(calc-liveness) + bb.(peephole) bb.(get-insns))) (defun true-const-p (arg) -- cgit v1.2.3