fix optimizer bug

Moving an expression that is referenced through a level of copy
propagation did not fix up a nested static distance correctly.

Closes PR 13355
This commit is contained in:
Matthew Flatt 2012-12-16 13:09:42 -07:00
parent bbfded59bf
commit ef824351a1
2 changed files with 24 additions and 5 deletions

View File

@ -1585,6 +1585,25 @@
f))) f)))
#f) #f)
;; check move through an intermediate variable:
(test-comp '(lambda (n)
(let ([p (+ n n)])
(if n
(let ([m (unsafe-fx- p 1)]
[t (- p p)])
(let ([q (- p p)]
[s m])
(+ p s q t)))
'ok)))
'(lambda (n)
(let ([p (+ n n)])
(if n
(let ([m (unsafe-fx- p 1)]
[t (- p p)])
(+ p m (- p p) t))
'ok))))
;; simple cross-module inlining ;; simple cross-module inlining
(test-comp `(module m racket/base (test-comp `(module m racket/base
(require racket/bool) (require racket/bool)

View File

@ -5603,8 +5603,6 @@ top_level_require_optimize(Scheme_Object *data, Optimize_Info *info, int context
return data; return data;
} }
/*========================================================================*/ /*========================================================================*/
/* expressions */ /* expressions */
/*========================================================================*/ /*========================================================================*/
@ -6662,13 +6660,15 @@ static Scheme_Object *do_optimize_info_lookup(Optimize_Info *info, int pos, int
o->cross_lambda = (j != orig_j); o->cross_lambda = (j != orig_j);
return (Scheme_Object *)o; return (Scheme_Object *)o;
} else if (SAME_TYPE(SCHEME_TYPE(n), scheme_local_type)) { } else if (SAME_TYPE(SCHEME_TYPE(n), scheme_local_type)) {
int pos, cross_lambda = (j != orig_j); int pos, cross_lambda = (j != orig_j), extra_delta = 0;
pos = SCHEME_LOCAL_POS(n); pos = SCHEME_LOCAL_POS(n);
if (info->flags & SCHEME_LAMBDA_FRAME) if (info->flags & SCHEME_LAMBDA_FRAME)
j--; /* because it will get re-added on recur */ j--; /* because it will get re-added on recur */
else if (info->flags & SCHEME_POST_BIND_FRAME) else if (info->flags & SCHEME_POST_BIND_FRAME) {
extra_delta = info->new_frame;
info = info->next; /* bindings are relative to next frame */ info = info->next; /* bindings are relative to next frame */
}
/* Marks local as used; we don't expect to get back /* Marks local as used; we don't expect to get back
a value, because chaining would normally happen on the a value, because chaining would normally happen on the
@ -6694,7 +6694,7 @@ static Scheme_Object *do_optimize_info_lookup(Optimize_Info *info, int pos, int
} else if (SAME_TYPE(SCHEME_TYPE(n), scheme_once_used_type)) { } else if (SAME_TYPE(SCHEME_TYPE(n), scheme_once_used_type)) {
/* Need to adjust delta: */ /* Need to adjust delta: */
delta = optimize_info_get_shift(info, pos); delta = optimize_info_get_shift(info, pos);
((Scheme_Once_Used *)n)->delta += delta; ((Scheme_Once_Used *)n)->delta += delta + extra_delta;
if (cross_lambda) ((Scheme_Once_Used *)n)->cross_lambda = 1; if (cross_lambda) ((Scheme_Once_Used *)n)->cross_lambda = 1;
} }
} }