summaryrefslogtreecommitdiffstats
path: root/opt.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-03-21 21:24:24 -0400
committerTavian Barnes <tavianator@tavianator.com>2019-03-21 21:24:24 -0400
commit4216dbac10887476feef287854e9e4037f2d1a59 (patch)
tree2f447b8cd4490f814b3a580e673aa88bdd5d9b4e /opt.c
parent1fbc0fab56f1a1f620d9697e8592f8f1cd023389 (diff)
downloadbfs-4216dbac10887476feef287854e9e4037f2d1a59.tar.xz
opt: Optimize redundant comma expressions
Diffstat (limited to 'opt.c')
-rw-r--r--opt.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/opt.c b/opt.c
index fd2dc3c..1ece9be 100644
--- a/opt.c
+++ b/opt.c
@@ -595,9 +595,11 @@ static struct expr *optimize_comma_expr(const struct opt_state *state, struct ex
if (expr_never_returns(lhs)) {
debug_opt(state, "-O1: reachability: %e <==> %e\n", expr, lhs);
return extract_child_expr(expr, &expr->lhs);
- }
-
- if (optlevel >= 2 && lhs->pure) {
+ } else if ((lhs->always_true && rhs == &expr_true)
+ || (lhs->always_false && rhs == &expr_false)) {
+ debug_opt(state, "-O1: redundancy elimination: %e <==> %e\n", expr, lhs);
+ return extract_child_expr(expr, &expr->lhs);
+ } else if (optlevel >= 2 && lhs->pure) {
debug_opt(state, "-O2: purity: %e <==> %e\n", expr, rhs);
return extract_child_expr(expr, &expr->rhs);
}