shithub: scc

Download patch

ref: 42a2ed50d61e736f6c8c34ad78089ae9f56d6534
parent: 475fdec2b580ce32a5e53a3d33c139e23d977b07
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Sep 1 16:42:25 EDT 2015

Add idempotent optimization

- and ~ operands are idempotent.

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -130,11 +130,13 @@
 	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 @@
 	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);
 }