scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 42a2ed50d61e736f6c8c34ad78089ae9f56d6534
parent 475fdec2b580ce32a5e53a3d33c139e23d977b07
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  1 Sep 2015 20:42:25 +0200

Add idempotent optimization

- and ~ operands are idempotent.

Diffstat:
cc1/expr.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -130,11 +130,13 @@ numericaluop(char op, Node *np) switch (BTYPE(np)) { case INT: case FLOAT: + if (op == ONEG && np->op == ONEG) + return np->left; if (op == OADD) return np; return simplify(op, np->type, np, NULL); default: - error("unary operator requires integer operand"); + error("unary operator requires numerical operand"); } } @@ -144,6 +146,8 @@ integeruop(char op, Node *np) np = eval(np); if (BTYPE(np) != INT) error("unary operator requires integer operand"); + if (op == OCPL && np->op == OCPL) + return np->left; return simplify(op, np->type, np, NULL); }