From 0689ed6d0d0d74f9ca62057290db3bda8622afba Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 28 Aug 2019 21:03:28 -0700 Subject: compiler: elide nil var intializaton. Virtual machine local variables registers don't require nil initialization. In cases when a complex variable initializer is known to return nil, we can elide the move instrution which moves that nil into the register. * share/txr/stdlib/compiler.tl (null-reg): New function. (compiler comp-let): Don't move the value of the output register of the init fragment into the variable, if that register is the null register t0. --- share/txr/stdlib/compiler.tl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'share') diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index 5553f293..60411e39 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -206,6 +206,9 @@ (or [*dedup* obj] (set [*dedup* obj] obj))) (t obj))) +(defun null-reg (reg) + (equal reg '(t 0))) + (defmeth compiler get-dreg (me obj) (let ((dobj (dedup obj))) (condlet @@ -748,8 +751,9 @@ (frag me.(compile bind.loc fenv form))) (when seq fenv.(rename-var tmp sym)) - (pend frag.code - (maybe-mov bind.loc frag.oreg)) + (pend frag.code) + (unless (null-reg frag.oreg) + (pend (maybe-mov bind.loc frag.oreg))) (set ffuns (uni ffuns frag.ffuns) fvars (uni fvars (if seq -- cgit v1.2.3