~ chicken-core (chicken-5) a5006d93b6697e4e38722376d87724c99ec251f8


commit a5006d93b6697e4e38722376d87724c99ec251f8
Author:     Peter Bex <peter@more-magic.net>
AuthorDate: Sun Feb 28 18:15:37 2016 +0100
Commit:     Evan Hanson <evhan@foldling.org>
CommitDate: Sun Feb 28 18:15:37 2016 +0100

    Fix excessive temporary generation
    
    In deeply nested if structures, we would generate a set of temporaries
    for each arm of the if, while the code would re-use temporaries.
    
    This means if each arm uses N temporaries, at a nesting depth of M we
    would generate N*2^M temporaries, instead of just N.
    
    This is especially clear in the generated code for core.scm; there is
    one C function with over 200 temporaries which uses less than 100!
    
    Signed-off-by: Evan Hanson <evhan@foldling.org>

diff --git a/core.scm b/core.scm
index 76419b43..77f306c8 100644
--- a/core.scm
+++ b/core.scm
@@ -2863,11 +2863,14 @@
 
 	  ((if ##core#cond)
 	   (let* ((test (walk (first subs) e e-count here boxes))
+		  (t0 temporaries)
 		  (a0 allocated)
 		  (x1 (walk (second subs) e e-count here boxes))
+		  (t1 temporaries)
 		  (a1 allocated)
 		  (x2 (walk (third subs) e e-count here boxes)))
 	     (set! allocated (+ a0 (max (- allocated a1) (- a1 a0))))
+	     (set! temporaries (+ t0 (max (- temporaries t1) (- t1 t0))))
 	     (make-node class params (list test x1 x2))))
 
 	  ((##core#switch)
Trap