From ce4b9b23a2faf3a7fa5dff032b934b3ded7d39c7 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 4 Aug 2023 06:59:02 -0700 Subject: compiler: bug: constant folding load-time dregs. The optimizer eliminates calls to pure library functions when all their arguments are D-registers. The call is made at compiled time and its value is inserted into the program as a constant (in a newly allocated D register). The bug is that we can't do this for a D register that is linked to a load-time value, because we don't know its value until run-time. * stdlib/optimize.tl (basic-blocks do-peephole-block): Add a constraint that none of the D registers can be a member of bb.lt-dregs, which holds the list of D registers that are used for load-time values. --- stdlib/optimize.tl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/optimize.tl b/stdlib/optimize.tl index a16403b9..702a4252 100644 --- a/stdlib/optimize.tl +++ b/stdlib/optimize.tl @@ -539,7 +539,8 @@ . @(all @(or (d @dn) @(with (t 0) dn nil)))) . @rest) - [%const-foldable% [bb.symvec idx]]) + [%const-foldable% [bb.symvec idx]] + [none dn (lop member bb.lt-dregs : cadr)]) (let* ((co bb.compiler) (dvec co.(get-datavec)) (fun [bb.symvec idx]) -- cgit v1.2.3