[gambit-list] Guile's new compiler

Marc Feeley feeley at iro.umontreal.ca
Thu Nov 5 07:29:56 EST 2015


You haven’t given the compiler much information to help it optimize…

Try:

(declare (standard-bindings))

(define (a x y)
  (map (lambda (c d) (+ c d)) x y))

It gives better inlining than (map + x y) .  I haven’t looked into the details of why, but it is the transformations in gsc/_ptree2.scm that are involved in the inlining.  Perhaps you could trace the code to see where the inlining is cut short.

Did you try this with Guile also to compare?

Marc


> On Nov 5, 2015, at 12:38 AM, Bradley Lucier <lucier at math.purdue.edu> wrote:
> 
> 
>> On Nov 4, 2015, at 10:26 PM, Marc Feeley <feeley at iro.umontreal.ca> wrote:
>> 
>> As far as I can tell, all of those optimizations are currently done by the Gambit compiler except for loop-invariant code motion and loop inversion.  I’m not sure how much those optimizations are useful however.
>> 
>> Marc
> 
> OK.
> 
> What about this example:
> 
> [Media-Mac-mini-3:~] lucier% cat crap.scm
> (define (a x y)
>  (map + x y))
> 
> [Media-Mac-mini-3:~] lucier% gsc -c -expansion crap
> Expansion:
> 
> (define a
>  (lambda (x y)
>    (let ((temp.0 +))
>      (if (and ('#<procedure #2 ##eq?> map '#<procedure #3 map>) ('#<procedure #4 ##procedure?> temp.0))
>          (letrec ((loop1.3 (lambda (x y temp.0 temp.4 temp.5)
>                              (if (and ('#<procedure #5 ##pair?> temp.4) ('#<procedure #5 ##pair?> temp.5))
>                                  (loop1.3 x y temp.0 ('#<procedure #6 ##cdr> temp.4) ('#<procedure #6 ##cdr> temp.5))
>                                  (if (and ('#<procedure #7 ##null?> temp.4) ('#<procedure #7 ##null?> temp.5))
>                                      (letrec ((loop2.6 (lambda (temp.0 temp.7 temp.8)
>                                                          (if (and ('#<procedure #5 ##pair?> temp.7) ('#<procedure #5 ##pair?> temp.8))
>                                                              (let ((x.9 (temp.0 ('#<procedure #8 ##car> temp.7) ('#<procedure #8 ##car> temp.8))))
>                                                                ('#<procedure #9 ##cons>
>                                                                 x.9
>                                                                 (loop2.6 temp.0 ('#<procedure #6 ##cdr> temp.7) ('#<procedure #6 ##cdr> temp.8))))
>                                                              '()))))
>                                        (loop2.6 temp.0 x y))
>                                      (map temp.0 x y))))))
>            (loop1.3 x y temp.0 x y))
>          (map temp.0 x y)))))
> 
> The gambit compiler doesn’t specialize +.
> 
> Or even
> 
> [Media-Mac-mini-3:~] lucier% cat crap.scm
> (define (a x y)
>  (map f64+ x y))
> [Media-Mac-mini-3:~] lucier% gsc -c -expansion crap
> Expansion:
> 
> (define a
>  (lambda (x y)
>    (let ((temp.0 f64+))
>      (if (and ('#<procedure #2 ##eq?> map '#<procedure #3 map>) ('#<procedure #4 ##procedure?> temp.0))
>          (letrec ((loop1.3 (lambda (x y temp.0 temp.4 temp.5)
>                              (if (and ('#<procedure #5 ##pair?> temp.4) ('#<procedure #5 ##pair?> temp.5))
>                                  (loop1.3 x y temp.0 ('#<procedure #6 ##cdr> temp.4) ('#<procedure #6 ##cdr> temp.5))
>                                  (if (and ('#<procedure #7 ##null?> temp.4) ('#<procedure #7 ##null?> temp.5))
>                                      (letrec ((loop2.6 (lambda (temp.0 temp.7 temp.8)
>                                                          (if (and ('#<procedure #5 ##pair?> temp.7) ('#<procedure #5 ##pair?> temp.8))
>                                                              (let ((x.9 (temp.0 ('#<procedure #8 ##car> temp.7) ('#<procedure #8 ##car> temp.8))))
>                                                                ('#<procedure #9 ##cons>
>                                                                 x.9
>                                                                 (loop2.6 temp.0 ('#<procedure #6 ##cdr> temp.7) ('#<procedure #6 ##cdr> temp.8))))
>                                                              '()))))
>                                        (loop2.6 temp.0 x y))
>                                      (map temp.0 x y))))))
>            (loop1.3 x y temp.0 x y))
>          (map temp.0 x y)))))
> 
> 




More information about the Gambit-list mailing list