Fix bug in CSE auxiliary definitions
* module/language/cps/cse.scm (compute-equivalent-subexpressions): When
CSE sees a definition like `(cons a b)', it will also record an
"auxiliary definition" for `(car x)', where x is the variable defined
by the cons, whereby calling `(car x)' can reduce to `a' if there is
no intervening effect that clobbers the definitions. However, when
the successor of the cons is a control-flow join, then any variables
defined there have multiple definitions. It's incorrect to add the
aux definition in that case.
* test-suite/tests/compiler.test ("cse auxiliary definitions"): New
test.
This commit is contained in:
parent
b02d1b08d7
commit
a2f5f9eda4
2 changed files with 56 additions and 16 deletions
|
|
@ -300,3 +300,40 @@
|
|||
(cons 't (if x 't 'f))
|
||||
(cons 'f (if x 't 'f)))))
|
||||
'(3 #t #f #nil ()))))
|
||||
|
||||
(with-test-prefix "cse auxiliary definitions"
|
||||
(define test-code
|
||||
'(begin
|
||||
(define count 1)
|
||||
(set! count count) ;; Avoid inlining
|
||||
|
||||
(define (main)
|
||||
(define (trampoline thunk)
|
||||
(let loop ((i 0) (result #f))
|
||||
(cond
|
||||
((< i 1)
|
||||
(loop (+ i 1) (thunk)))
|
||||
(else
|
||||
(unless (= result 42) (error "bad result" result))
|
||||
(newline)
|
||||
result))))
|
||||
(define (test n)
|
||||
(let ((matrix (make-vector n)))
|
||||
(let loop ((i (- n 1)))
|
||||
(when (>= i 0)
|
||||
(vector-set! matrix i (make-vector n 42))
|
||||
(loop (- i 1))))
|
||||
(vector-ref (vector-ref matrix 0) 0)))
|
||||
|
||||
(trampoline (lambda () (test count))))
|
||||
main))
|
||||
|
||||
(define test-proc #f)
|
||||
(pass-if "compiling test works"
|
||||
(begin
|
||||
(set! test-proc (compile test-code))
|
||||
(procedure? test-proc)))
|
||||
|
||||
(pass-if-equal "test terminates without error" 42
|
||||
(test-proc)))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue