1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 22:10:21 +02:00

CSE in tail position

* module/language/tree-il/cse.scm (singly-valued-expression?, cse):
  Allow CSE to propagate lexicals to tail positions, if the expression
  is singly-valued.
This commit is contained in:
Andy Wingo 2012-05-15 17:20:01 +02:00
parent 9b1750ed42
commit dc1ee62046

View file

@ -154,6 +154,21 @@
(($ <const> _ (? boolean?)) #t)
(_ (eq? ctx 'test))))
(define (singly-valued-expression? x ctx)
(match x
(($ <const>) #t)
(($ <lexical-ref>) #t)
(($ <void>) #t)
(($ <lexical-ref>) #t)
(($ <primitive-ref>) #t)
(($ <module-ref>) #t)
(($ <toplevel-ref>) #t)
(($ <application> _
($ <primitive-ref> _ (? singly-valued-primitive?))) #t)
(($ <application> _ ($ <primitive-ref> _ 'values) (val)) #t)
(($ <lambda>) #t)
(_ (eq? ctx 'value))))
(define* (cse exp)
"Eliminate common subexpressions in EXP."
@ -371,7 +386,7 @@
=> (lambda (exp)
(log 'propagate-test ctx (unparse-tree-il exp))
(values exp db*)))
((and (eq? ctx 'value)
((and (singly-valued-expression? exp ctx)
(find-dominating-lexical exp effects env db))
=> (lambda (exp)
(log 'propagate-value ctx (unparse-tree-il exp))