optimizer: transform (if v x v) to (if v x #f)
This commit is contained in:
parent
55c040cf3a
commit
82ffd40592
|
@ -1361,10 +1361,34 @@
|
||||||
(if r r (something-else)))
|
(if r r (something-else)))
|
||||||
(a1)
|
(a1)
|
||||||
(a2)))
|
(a2)))
|
||||||
'(lambda (x) (if (if (something) #t (something-else))
|
'(lambda (x) (if (if (something) #t (something-else))
|
||||||
|
(a1)
|
||||||
|
(a2))))
|
||||||
|
|
||||||
|
(test-comp '(lambda (x) (if (if x x (something-else))
|
||||||
|
(a1)
|
||||||
|
(a2)))
|
||||||
|
'(lambda (x) (if (if x #t (something-else))
|
||||||
(a1)
|
(a1)
|
||||||
(a2))))
|
(a2))))
|
||||||
|
|
||||||
|
(test-comp '(lambda (x) (if x (something-else) x))
|
||||||
|
'(lambda (x) (if x (something-else) #f)))
|
||||||
|
|
||||||
|
(test-comp '(lambda (x) (if (if x #t #f)
|
||||||
|
(a1)
|
||||||
|
(a2)))
|
||||||
|
'(lambda (x) (if x
|
||||||
|
(a1)
|
||||||
|
(a2))))
|
||||||
|
|
||||||
|
(test-comp '(lambda (x) (if (if x x x)
|
||||||
|
(a1)
|
||||||
|
(a2)))
|
||||||
|
'(lambda (x) (if x
|
||||||
|
(a1)
|
||||||
|
(a2))))
|
||||||
|
|
||||||
(test-comp '(if (let ([z (random)]) null) 1 2)
|
(test-comp '(if (let ([z (random)]) null) 1 2)
|
||||||
'(if (let ([z (random)]) #t) 1 2))
|
'(if (let ([z (random)]) #t) 1 2))
|
||||||
|
|
||||||
|
|
|
@ -3620,17 +3620,24 @@ static Scheme_Object *optimize_branch(Scheme_Object *o, Optimize_Info *info, int
|
||||||
tb = b->tbranch;
|
tb = b->tbranch;
|
||||||
fb = b->fbranch;
|
fb = b->fbranch;
|
||||||
|
|
||||||
|
/* Convert (if <id> expr <id>) to (if <id> expr #f) */
|
||||||
|
if (SAME_TYPE(SCHEME_TYPE(t), scheme_local_type)
|
||||||
|
&& SAME_TYPE(SCHEME_TYPE(fb), scheme_local_type)
|
||||||
|
&& (SCHEME_LOCAL_POS(t) == SCHEME_LOCAL_POS(fb))) {
|
||||||
|
fb = scheme_false;
|
||||||
|
}
|
||||||
|
|
||||||
if (context & OPT_CONTEXT_BOOLEAN) {
|
if (context & OPT_CONTEXT_BOOLEAN) {
|
||||||
/* For test position, convert (if <expr> #t #f) to <expr> */
|
/* For test position, convert (if <id> <id> expr) to (if <id> #t expr) */
|
||||||
if (SAME_OBJ(tb, scheme_true) && SAME_OBJ(fb, scheme_false))
|
|
||||||
return scheme_optimize_expr(t, info, context);
|
|
||||||
|
|
||||||
/* Convert (if <id> <id> expr) to (if <id> #t expr) */
|
|
||||||
if (SAME_TYPE(SCHEME_TYPE(t), scheme_local_type)
|
if (SAME_TYPE(SCHEME_TYPE(t), scheme_local_type)
|
||||||
&& SAME_TYPE(SCHEME_TYPE(tb), scheme_local_type)
|
&& SAME_TYPE(SCHEME_TYPE(tb), scheme_local_type)
|
||||||
&& (SCHEME_LOCAL_POS(t) == SCHEME_LOCAL_POS(tb))) {
|
&& (SCHEME_LOCAL_POS(t) == SCHEME_LOCAL_POS(tb))) {
|
||||||
b->tbranch = tb = scheme_true;
|
tb = scheme_true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Convert (if <expr> #t #f) to <expr> */
|
||||||
|
if (SAME_OBJ(tb, scheme_true) && SAME_OBJ(fb, scheme_false))
|
||||||
|
return scheme_optimize_expr(t, info, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
optimize_info_seq_init(info, &info_seq);
|
optimize_info_seq_init(info, &info_seq);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user