summaryrefslogtreecommitdiffstats
path: root/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-06-08 22:22:09 -0400
committerTavian Barnes <tavianator@tavianator.com>2016-06-08 22:30:59 -0400
commit593e2135a98b66999f3143c70dd5169701972906 (patch)
tree66274beb23e532d6e65a31bccd434bb7d6aba2c4 /parse.c
parentfcc1a4bb999856574404c629e59fd949ffe6cf3d (diff)
downloadbfs-593e2135a98b66999f3143c70dd5169701972906.tar.xz
Optimize ( ! x , y ) <==> ( x , y )
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/parse.c b/parse.c
index 0caa66e..cccdacf 100644
--- a/parse.c
+++ b/parse.c
@@ -1604,8 +1604,20 @@ static struct expr *parse_clause(struct parser_state *state) {
* Create a "comma" expression.
*/
static struct expr *new_comma_expr(const struct parser_state *state, struct expr *lhs, struct expr *rhs, char **argv) {
- if (state->cmdline->optlevel >= 2) {
- if (lhs->pure) {
+ int optlevel = state->cmdline->optlevel;
+ if (optlevel >= 1) {
+ if (lhs->eval == eval_not) {
+ debug_opt(state, "-O1: ignored result: (%s %e %e) <==> (%s %e %e)\n",
+ argv[0], lhs, rhs,
+ argv[0], lhs->rhs, rhs);
+
+ struct expr *old = lhs;
+ lhs = old->rhs;
+ old->rhs = NULL;
+ free_expr(old);
+ }
+
+ if (optlevel >= 2 && lhs->pure) {
debug_opt(state, "-O2: purity: (%s %e %e) <==> %e\n", argv[0], lhs, rhs, rhs);
free_expr(lhs);
return rhs;