optimize (if (if <test> #t #f) <t> <f>) to (if <test> #t #f); this pattern happens with 'and' and constant folding

svn: r14230
This commit is contained in:
Matthew Flatt 2009-03-23 13:17:46 +00:00
parent 3e039705fa
commit 7e6dc9b40e

View File

@ -2902,6 +2902,16 @@ static Scheme_Object *optimize_branch(Scheme_Object *o, Optimize_Info *info)
} else
t = scheme_optimize_expr(t, info);
/* For test position, convert (if <expr> #t #f) to <expr> */
while (1) {
if (SAME_TYPE(SCHEME_TYPE(t), scheme_branch_type)
&& SAME_OBJ(((Scheme_Branch_Rec *)t)->tbranch, scheme_true)
&& SAME_OBJ(((Scheme_Branch_Rec *)t)->fbranch, scheme_false))
t = ((Scheme_Branch_Rec *)t)->test;
else
break;
}
if (SCHEME_TYPE(t) > _scheme_compiled_values_types_) {
if (SCHEME_FALSEP(t))
return scheme_optimize_expr(fb, info);