summaryrefslogtreecommitdiffstats
path: root/opt.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-03-20 18:29:16 -0400
committerTavian Barnes <tavianator@tavianator.com>2019-03-20 18:29:16 -0400
commit344f9c2f844b20a8ba206595c28429a196383e23 (patch)
tree03981ef52bab3196c43fbc87e30549cf19f5eb68 /opt.c
parent2e10b1d55bccbbe3de811df91a70772978e76abf (diff)
downloadbfs-344f9c2f844b20a8ba206595c28429a196383e23.tar.xz
opt: Replace -a -false/-o -true with -not when possible
Diffstat (limited to 'opt.c')
-rw-r--r--opt.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/opt.c b/opt.c
index dd98ca0..fd2dc3c 100644
--- a/opt.c
+++ b/opt.c
@@ -50,6 +50,7 @@
static char *fake_and_arg = "-a";
static char *fake_or_arg = "-o";
+static char *fake_not_arg = "!";
/**
* A contrained integer range.
@@ -433,6 +434,14 @@ static struct expr *optimize_and_expr(const struct opt_state *state, struct expr
} else if (lhs->always_false) {
debug_opt(state, "-O1: short-circuit: %e <==> %e\n", expr, lhs);
return extract_child_expr(expr, &expr->lhs);
+ } else if (lhs->always_true && rhs == &expr_false) {
+ debug_opt(state, "-O1: strength reduction: %e <==> ", expr);
+ struct expr *ret = extract_child_expr(expr, &expr->lhs);
+ ret = negate_expr(ret, &fake_not_arg);
+ if (ret) {
+ debug_opt(state, "%e\n", ret);
+ }
+ return ret;
} else if (optlevel >= 2 && lhs->pure && rhs == &expr_false) {
debug_opt(state, "-O2: purity: %e <==> %e\n", expr, rhs);
return extract_child_expr(expr, &expr->rhs);
@@ -493,6 +502,14 @@ static struct expr *optimize_or_expr(const struct opt_state *state, struct expr
} else if (rhs == &expr_false) {
debug_opt(state, "-O1: disjunctive syllogism: %e <==> %e\n", expr, lhs);
return extract_child_expr(expr, &expr->lhs);
+ } else if (lhs->always_false && rhs == &expr_true) {
+ debug_opt(state, "-O1: strength reduction: %e <==> ", expr);
+ struct expr *ret = extract_child_expr(expr, &expr->lhs);
+ ret = negate_expr(ret, &fake_not_arg);
+ if (ret) {
+ debug_opt(state, "%e\n", ret);
+ }
+ return ret;
} else if (optlevel >= 2 && lhs->pure && rhs == &expr_true) {
debug_opt(state, "-O2: purity: %e <==> %e\n", expr, rhs);
return extract_child_expr(expr, &expr->rhs);