optimizer: optimizes the argument of not in a Boolean context

This enables more reductions, for example: (not (if x y 2)) => (not (if x y #t))
This commit is contained in:
Gustavo Massaccesi 2014-06-17 21:56:44 -03:00 committed by Matthew Flatt
parent 23f6d1a651
commit 50ef3a8295
2 changed files with 11 additions and 4 deletions

View File

@ -1335,6 +1335,9 @@
(quote-syntax no!))
''ok)
(test-comp '(lambda (x) (not (if x #f 2)))
'(lambda (x) (not (if x #f #t))))
(test-comp '(lambda (x) (if x x #f))
'(lambda (x) x))
(test-comp '(lambda (x) (if (cons 1 x) 78 78))

View File

@ -2724,7 +2724,7 @@ static Scheme_Object *optimize_application2(Scheme_Object *o, Optimize_Info *inf
if (le)
return le;
le = scheme_optimize_expr(app->rator, info, sub_context);
le = scheme_optimize_expr(app->rator, info, 0);
app->rator = le;
{
@ -2734,9 +2734,13 @@ static Scheme_Object *optimize_application2(Scheme_Object *o, Optimize_Info *inf
return le;
}
ty = wants_local_type_arguments(app->rator, 0);
if (ty)
sub_context |= (ty << OPT_CONTEXT_TYPE_SHIFT);
if (SAME_PTR(scheme_not_prim, app->rator)){
sub_context = OPT_CONTEXT_BOOLEAN;
} else {
ty = wants_local_type_arguments(app->rator, 0);
if (ty)
sub_context |= (ty << OPT_CONTEXT_TYPE_SHIFT);
}
le = scheme_optimize_expr(app->rand, info, sub_context);
app->rand = le;