~ chicken-core (chicken-5) eb97d20553fbce6561ce77a647821230b8faade3


commit eb97d20553fbce6561ce77a647821230b8faade3
Author:     Peter Bex <peter@more-magic.net>
AuthorDate: Sun Feb 28 18:13:21 2016 +0100
Commit:     Evan Hanson <evhan@foldling.org>
CommitDate: Sun Feb 28 18:13:21 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 compiler.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/compiler.scm b/compiler.scm
index 3ac40e91..301dcfef 100644
--- a/compiler.scm
+++ b/compiler.scm
@@ -2775,11 +2775,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