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:
parent
23f6d1a651
commit
50ef3a8295
|
@ -1335,6 +1335,9 @@
|
||||||
(quote-syntax no!))
|
(quote-syntax no!))
|
||||||
''ok)
|
''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))
|
(test-comp '(lambda (x) (if x x #f))
|
||||||
'(lambda (x) x))
|
'(lambda (x) x))
|
||||||
(test-comp '(lambda (x) (if (cons 1 x) 78 78))
|
(test-comp '(lambda (x) (if (cons 1 x) 78 78))
|
||||||
|
|
|
@ -2724,7 +2724,7 @@ static Scheme_Object *optimize_application2(Scheme_Object *o, Optimize_Info *inf
|
||||||
if (le)
|
if (le)
|
||||||
return le;
|
return le;
|
||||||
|
|
||||||
le = scheme_optimize_expr(app->rator, info, sub_context);
|
le = scheme_optimize_expr(app->rator, info, 0);
|
||||||
app->rator = le;
|
app->rator = le;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -2734,9 +2734,13 @@ static Scheme_Object *optimize_application2(Scheme_Object *o, Optimize_Info *inf
|
||||||
return le;
|
return le;
|
||||||
}
|
}
|
||||||
|
|
||||||
ty = wants_local_type_arguments(app->rator, 0);
|
if (SAME_PTR(scheme_not_prim, app->rator)){
|
||||||
if (ty)
|
sub_context = OPT_CONTEXT_BOOLEAN;
|
||||||
sub_context |= (ty << OPT_CONTEXT_TYPE_SHIFT);
|
} 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);
|
le = scheme_optimize_expr(app->rand, info, sub_context);
|
||||||
app->rand = le;
|
app->rand = le;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user