diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2017-07-21 19:09:10 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2017-07-21 19:09:10 -0400 |
commit | 462589f69859354a9c623cad9015821e769beecb (patch) | |
tree | 805ab7e0989617098c9311e0386963b37142084c /parse.c | |
parent | 4a245d3885f99169649cc45e2d1abe606c249d22 (diff) | |
download | bfs-462589f69859354a9c623cad9015821e769beecb.tar.xz |
Fix a couple terrible optimizer bugs
Just because an expression is always true or false, doesn't mean we can
execute it more often than it otherwise would be, unless it's also pure.
But that's equivalent to being identically -true/-false, so just check
that.
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -2568,7 +2568,7 @@ static struct expr *new_and_expr(const struct parser_state *state, struct expr * debug_opt(state, "-O1: short-circuit: (%s %e %e) <==> %e\n", argv[0], lhs, rhs, lhs); free_expr(rhs); return lhs; - } else if (optlevel >= 2 && rhs->always_false && lhs->pure) { + } else if (optlevel >= 2 && lhs->pure && rhs == &expr_false) { debug_opt(state, "-O2: purity: (%s %e %e) <==> %e\n", argv[0], lhs, rhs, rhs); free_expr(lhs); return rhs; @@ -2664,7 +2664,7 @@ static struct expr *new_or_expr(const struct parser_state *state, struct expr *l } else if (rhs == &expr_false) { debug_opt(state, "-O1: disjunctive syllogism: (%s %e %e) <==> %e\n", argv[0], lhs, rhs, lhs); return lhs; - } else if (optlevel >= 2 && rhs->always_true && lhs->pure) { + } else if (optlevel >= 2 && lhs->pure && rhs == &expr_true) { debug_opt(state, "-O2: purity: (%s %e %e) <==> %e\n", argv[0], lhs, rhs, rhs); free_expr(lhs); return rhs; |